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.

Featured Resources:

Related Articles:

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

    Microsoft Reference Architecture for a High Availability SharePoint Server 2016 Farm in Azure

    The Azure CAT Patterns & Practices team has published a new reference architecture for deploying and running a high availability SharePoint Server 2016 farm in Azure. It provides prescriptive guidance including the following topics: Architecture resources necessary for the deployment, including resources. Scalability considerations. Availability considerations. Manageability considerations. Security considerations. Like all reference architectures that […]

    Downloads

      FREE eG Enterprise Logon Simulator for Citrix XenApp and XenDesktop

      Fast, free and incredibly useful. Coming in summer 2017. 14Synthetic logon simulation tool for monitoring, diagnosis, alerting and reporting of Citrix logon performance Quick SaaS deployment – be up and running in minutes Web-based monitoring console Supports logon through StoreFront or NetScaler Gateway Best-suited for Citrix XenApp 6.5, 7.x and XenDesktop 7.x Free forever, no […]

      On-Demand Webinars

        Latest Videos

          Live from the #AWS NY Summit | AWS SAM Local Launch

          Live from the AWS Summit in NYC, Tara Walker and Chris Munns discuss the new launch of AWS SAM Local on twitch.tv/aws. Host: Tara Walker Guest: Chris Munns, Sr Developer Advocate for AWS Serverless Date: August 14, 2017 For more information on the AWS Twitch Channel and upcoming live coding episodes, visit https://aws.amazon.com/twitch. To learn more […]

          Views All IT News on DABCC.com
          Views All IT Videos on DABCC.com
          Win a Tesla P100D

          Visit our Sponsors!

          Close