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:

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

    steadyPRINT Data Sheet – centralized printer administration, monitoring and reliability!

    All In One Tool. Organize all tasks of your printer management centrally – intuitively and clearly structured: Management of the printer connections, driverless printing, monitoring & reporting of the complete print environment, print server reliability and migration and many more. Off er your users different options to simply and flexibly print their documents in each […]

    Downloads

      Download Universal Desktop Converter 3 (UDC3) – Turn PC in to Securely Managed End-Point

      The Universal Desktop Converter 3 (UDC3) thin client software provides a highly effective alternative to traditional thin client hardware. Download Universal Desktop Converter 3 (UDC3) The software is installed as the operating system on PCs, notebooks and selected thin clients, and turns the hardware into a powerful software based and universally deployable thin client allowing […]

      On-Demand Webinars

        Monitor Managing the End User Experience with GPU-Powered Insights – Citrix Ready On-Demand Webinar

        An On-Demand Citrix-Ready Webinar GPU technology improves Citrix virtual desktops and applications, but to truly deliver an immersive user experience that scales, organizations need to manage the complete GPU deployment lifecycle – from designing the infrastructure, to managing and optimizing a production environment, to responding to user issues dynamically, in real-time. eG Innovations in partnership with […]

        Latest Videos

          Turbonomic Feature Video #10 – The Green Circle IT Community

          The Turbonomic Platform can do a whole lot and we decided it would be good to walk you through our customers top 10 favorite features within the platform Feature #10 is our AWESOME community of IT thought leaders, technology evangelists, and experts. Access the community for support, questions, how-to’s and much more right from our […]

          Views All IT News on DABCC.com
          Views All IT Videos on DABCC.com
          Close