Pages

Wednesday, January 29, 2014

Powershell script to create a report for whether or not a Citrix Xenapp Hotfix is installed on Citrix Xenapp farm servers or not


One of the second biggest pain for me as a farm administrator has always been to figure out if the XenApp Servers in the farm do have the latest rollup (or hotfix installed. And which are the servers where the latest roll up is not installed. The biggest pain of course is to install it remotely on all the XenApp servers ( I am still working in that one).

So I have this script that creates a report for a particular rollup pack or hotfix telling which servers have the hotfix installed and which don’t. It also creates a list of servers where the hotfix is not installed so I can install the hotfix on those servers.

I have tested this script on XenApp 6.0 farm. I ran the script from a XenApp server in the farm.



# Script to create a report on whether the hotfix is installed or not on the
# XenApp servers
# Created by: Ruby Nahal


# Register Addins if missing
$snapin = Get-PSSnapin | where {$_.name -eq 'Citrix.Common.Commands'}
if($snapin -eq $null){ Add-PSSnapin Citrix.Common.Commands }
$snapin = Get-PSSnapin | where {$_.name -eq 'Citrix.XenApp.Commands'}
if($snapin -eq $null){ Add-PSSnapin Citrix.XenApp.Commands }

$farm = Get-XAfarm          #get farm info
$servers = Get-XAServer    # get all the xenapp servers in the farm
[string]$CXAName              # string object to store the Xenapp server name
$logfile = "C:\Support\XAreport.txt"         # log file to store CXA name and if the hotfix is installed or not
$CXAList = "C:\Support\CXAlist.txt"                   #list of servers that do not have the hotfix installed

Foreach($CXA in $servers)            #run for each CXA or Xenapp server in the farm
{
[Boolean]$RUisInstalled = $false    #boolean variable to check the status of hotfix on the server
$CXAName = $CXA.Servername                        #Get the server name for the CXA in the current loop
Write-Output $CXAName                                # write the cxa name

#function XenappHotfixRU2Report([string]$HotfixName)           #can also use this script as a function for multiple hotfixes
#       {
    # Get current computername and XenServer object
    [String]$HotfixName = 'XA600W2K8R2X64R02'          #hotfix in question - will be commented out if used as the function
   
    foreach($hotfix in (Get-XAServerHotFix -ServerName $CXAName)) #run for each hotfix installed on the server
          {
           
        if($hotfix.HotfixName -eq $HotfixName) #if hotfix name is equal to the $hotfixname set the boolean variable to true
                             {
                             $RUisInstalled = $true
                             }
                   else
                             {
                             echo ".." # else, basically do nothing
                             }
          }
                   echo "'n****** $CXAName *******" | Out-File $logfile -Append -Width 240 # write the CXA name to the log file
                   if ($RUisInstalled# tell us if hotfix is installed or not by writing it to the log file
                             {
                             echo "Rollup Installed" | Out-File $logfile -Append -Width 240
                             }
                   Else
                             {
                             echo "Rollup was Not Installed" | Out-File $logfile -Append -Width 240
                             echo $CXAName | Out-File $CXAList -Append -Width 240
                             }
#       }
          #XenappHotfixRU2Report 'XA600W2K8R2X64R02'

}

No comments:

Post a Comment