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:

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

    NEW VMware Whitepaper – Deliver Office 365 in VMware Horizon 7 with Published Applications

    By Frank Anderson, End-User-Computing Solutions Architect, Desktop Technical Marketing, VMware and Cindy Heyer Carroll, Technical Writer, End-User-Computing Technical Marketing, VMware We are excited to announce a new white paper, Best Practices for Delivering Microsoft Office 365 in VMware Horizon 7 with Published Applications, now available to help you avoid risks that can occur during setup […]

    Downloads

      FREE Tool – Troubleshoot Remote Desktop Connections

      Everyone wants to do things in a simple and effortless way. From a child that plays with a remote controlled car to a photographer who uses a drone for landscape photography, nowadays nearly everything can be automated or operated remotely. And system administration is no exception. Troubleshooting remote desktops is now as easy as using […]

      On-Demand Webinars

        How analyzing data patterns can improve IT service delivery – On-Demand Webinar

        Watch this webinar to know how to use Analytics Plus to- 1. Identify data patterns using visual analysis to spot trends easily. 2. Correlate data from multiple sources and get unified visibility into your IT. 3. Create live dashboards to make continuous improvements in ITSM processes. This video is from the fine folks at ManageEngine

        Latest Videos

          VMware TrustPoint and AirWatch Integration Demo Video

          Learn how out-of-the-box integration of VMware TrustPoint and AirWatch further enhances securing and managing mobile, desktop and server environments, and dynamically drives policy configuration changes across the organization for even stronger compliance and faster threat containment. This video is from the fine folks at VMware EUC.

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

          Visit our Sponsors!


          Close