Home Applications Finding Offline Citrix XenApp Servers Using Microsoft PowerShell Part 1 of 4 (Updated May 21, 2011)

Finding Offline Citrix XenApp Servers Using Microsoft PowerShell Part 1 of 4 (Updated May 21, 2011)

0
0

May 21, 2011: I found a bug in the script where it did not work under all conditions for XenApp5 and XenApp 6.  I have changed the script to a version that, so far, has worked in all conditions tested.

Recently I was asked how to use PowerShell to get a list of offline Citrix XenApp servers. Being new to PowerShell, this gave me an opportunity to use some of my new knowledge. At the time this article is being written, I have been working with PowerShell for less than one month. Feel free to offer suggestions for how to improve the script in this four part article series.

To use PowerShell with XenApp 6, you will need the XenApp 6 PowerShell SDK (Software Development Kit) available from http://tinyurl.com/XA6PSSDK (Figure 1).
Figure 1
To use PowerShell with XenApp 5, you will need the XenApp Commands Technology Preview (v3) available from http://tinyurl.com/XA5CTPv3 (MyCitrix login required) (Figure 2).
Figure 2
Note: The scripts in this article should work for XenApp 6 and XenApp 5 for Windows Server 2008 and XenApp 5 for Windows Server 2003.
To develop and test this script, my lab setup includes three servers running Citrix XenApp 6 for Microsoft Windows Server 2008 R2 SP1. The XenApp server names are XenApp1, XenApp2 and XenApp3. Only XenApp1 is powered on. This gives two offline servers to test the script against.
In their PowerShell cmdlets (pronounced CommandLets), Citrix does not have a specific cmdlet that returns a list of offline servers. There are only two Citrix cmdlets that are needed in order to generate this list. The first cmdlet is Get-XAServer which returns a list of all XenApp servers (Online and Offline) in a XenApp farm (Figure 3).
Figure 3
 
Note: Get-XAServer returns 21 properties, of which only one is used by this script: ServerName. The PowerShell command line in Figure 3 takes the results of Get-XAServer, selects just the ServerName property, sorts the results in alphabetical order by ServerName and then displays the results in a formatted table displaying only the ServerName property.
The second cmdlet needed is Get-XAZone. This cmdlet returns a list of all the Zones in a XenApp farm. The reason this cmdlet is needed is that the Get-XAServer cmdlet has a switch –OnlineOnly that, believe it or not, returns a list of XenApp servers that are online. But, that switch requires the –ZoneName parameter. Combining Get-XAZone piped to Get-XAServer with the –OnlineOnly switch will return a list of online servers for every Zone in a XenApp farm (Figure 4).
Figure 4
 
Didn’t I just say the Get-XAServer cmdlet with the –OnlineOnly switch required the –ZoneName parameter? Yes I did. One of the many smart things that PowerShell handles under the covers is seeing that both Get-XAZone and Get-XAServer have the –ZoneName parameter in common. How does Get-XAServer automatically handle this? To find out, I typed Get-Help Get-XAServer –full and scrolled down to –ZoneName (Figure 5). I saw that –ZoneName accepts pipeline input by property name.
Figure 5
Note: I learned this from Don Jones, PowerShell MVP at The Experts Conference 2011 in his pre-conference PowerShell Deep-Dive Workshop.
This is part of the “magic” of PowerShell, handling stuff under the covers to make working in PowerShell less complicated.
Since Citrix does not provide, at this time, an –OfflineOnly switch, I have what is needed to build a list of offline servers. I have a list of all servers in the farm and a list of servers that are online. Any server that is in the all servers list but not in the online servers list is an offline server. This is fairly easy to do in PowerShell.
First, get the list of all servers in the farm sorted by ServerName.
$AllXAServers = Get-XAServer | Sort-Object ServerName

$XAServers = @()
ForEach( $XAServer in $AllXAServers )
{
       $XAServers += $XAServer.ServerName
}

Next, get all the online servers, also sorted by ServerName.
$OnlineXAServers = Get-XAZone | Get-XAServer –OnlineOnly | Sort-Object ServerName

$OnlineServers = @()
ForEach( $OnlineServer in $OnlineXAServers )
{
       $OnlineServers += $OnlineServer.ServerName
}

Create an array to hold the offline servers.
$OfflineServers = @()
Compare the array of online servers to the array of all servers. If a server is not in the online array, then it is offline.

ForEach( $Server in $XAServers )
{
       If( $OnLineServers -notcontains $Server )
       {
              $OfflineServers += $Server
       }
}

 
Display the list of offline servers.
Write-Output $OfflineServers
The entire script being run in my lab:

$AllXAServers = Get-XAServer | Sort-Object ServerName
 
$XAServers = @()
ForEach( $XAServer in $AllXAServers )
{
       $XAServers += $XAServer.ServerName
}
 
$OnlineXAServers = Get-XAZone | Get-XAServer -OnlineOnly | Sort-Object ServerName
 
$OnlineServers = @()
ForEach( $OnlineServer in $OnlineXAServers )
{
       $OnlineServers += $OnlineServer.ServerName
}
 
$OfflineServers = @()
ForEach( $Server in $XAServers )
{
       If( $OnLineServers -notcontains $Server )
       {
              $OfflineServers += $Server
       }
}
 
Write-Output $OfflineServers

 
Which produces the following output (Figure 6):
Figure 6
As it stands, the script is fully functional, works and produces the desired output – a list of offline servers in the XenApp farm. But, the script is not really as good as it could be and could create a Resume Generating Event if run on a large XenApp farm with zones spanning countries or continents. The script can be a lot better. Part 2 in this series will look at making the script better.

 

More Resources:

Categories:
DABCC DABCC.com, the world leader in sharing the finest Virtualization & Cloud news and support resources. #Citrix, #VMware, #Microsoft, #Mobility and much more! Brought to you by @douglasabrown & team!
| LATEST RESOURCES

White Papers

    Optimizing Virtual Infrastructure Storage Systems with Xangati ESP

    IN SEARCH OF BETTER TOOLS FOR OPTIMIZING EXPANSIVE ENTERPRISE STORAGE Virtualized infrastructures span servers, switches, storage systems and client devices. Of these four categories, storage systems are the most challenging to correctly size, configure and operate. That’s why IT administrators who manage complex virtual and cloud environments rely on Xangati ESP. Xangati’s real-time monitoring and analysis platform […]

    Downloads

      Download AppEnsure Free Application Response Time And Throughput In Virtualized And Cloud Environments

      Download AppEnsure: Application Response Time And Throughput In Virtualized And Cloud Environments.  AppEnsure is a Citrix Startup Accelerator company! AppEnsure provides APM for IT Operations to proactively manage end-user experience. AppEnsure uniquely correlates the real end-user response time experience with the application-delivery infrastructure performance, providing contextual, actionable intelligence to reduce resolution time by 95% of […]

      On-Demand Webinars

        Sneak Peek: Blob Storage for SoftNAS Cloud on Azure – The Video

        We’re always adding new and exciting features to SoftNAS Cloud. In this video, we show you a sneak peek of how SoftNAS Cloud front ends Azure Blob Storage with NFS, CIFS/SMB, iSCSI and AFP support. Learn more at www.softnas.com/azure


        Close