Recently I’ve responded to a number of posts on the Citrix forums where the question was solved by using PowerShell. I think there are still a lot of people who are running XenApp 5 and there are also a lot of people who haven’t yet started using PowerShell.
So in this post I will explain the very basics of how to start using PowerShell on XenApp.
A word or warning first. PowerShell, as the name says, is very powerful. You can do some major damage if you run the wrong command or script against your farm. In general you are safe with Get commands as these simply pull information from the farm but always test commands and scripts in a non-production environment before running against your production farm.
XenApp 5
To install for Windows 2008 use Server Manager to add the feature.
To install for Windows 2003 you must install the Windows Management Framework which is available for download at KB968929
Once you have Windows PowerShell installed you need to install the Citrix Power SDK which you can download from here (MyCitrix ID required). It is called Tech Preview 3 Release but as far as I know this is the latest PowerShell SDK for XenApp and it never went past Tech Preview.
.NET Framework 3.5 SP1A is a prerequisite of installing the PowerShell SDK.
XenApp 6 and 6.5
With Windows 2008 R2 PowerShell comes installed by default so you do not need to do anything to add it.
You still have to install the correct XenApp PowerShell SDK. Download it here for XenApp 6 and here for XenApp 6.5
When you run the install you will be given the option to update the PowerShell signing policy of the server. If you do not tick this option then certain scripts in the SDK will not run.
If you are writing your own PowerShell scripts and you are not signing them then you need to set the signing policy to unsigned, I will show you how to do this later.
PowerShell Basics
Now you have all the right components installed you are ready to start using PowerShell.
If you want to use the XenApp cmdlets (essentially the XenApp PowerShell commands) you must launch the correct PowerShell console.
You will find this in Start –> All Programs –>Citrix
If you don’t use these shortcuts to launch PowerShell the XenApp cmdlets will not load and you will not be able to use the XenApp PowerShell commands.
You can manually load the cmdlets using the following command, if you are running PowerShell commands in a script you need to use this command at the beginning of your script.
[code lang=”powershell”]
#
Add-PSSnapin Citrix.*
#
[/code]
Once you have the XenApp cmdlets loaded you can use the following command to get a list of the available commands
[code lang=”powershell”]
#
Get-Command -Module Citrix.*
#
[/code]
Or if you know part of the command you can use wildcards to give you a list of all the commands that are similar.
[code lang=”powershell”]
#
Get-Command *get-xa*
#
[/code]
Using the Get-Help command followed by a command name will give you all the help information about that command.
[code lang=”powershell”]
#
Get-Help Get-XAApplicationReport
#
[/code]
Follow Get-Help with -full or -examples for the full help text or example commands.
[code lang=”powershell”]
#
Get-Help -full Get-XAApplicationReport
#
[/code]
Get-XAApplicationReport is a good command to start playing around with.
[code lang=”powershell”]
#
Get-XAApplicationReport
#
[/code]
Follow this command with an asterisk to get details of all your published applications (may take a while to run if you have a lot) or follow it by a specific application name to just get information about one particular published app.
You can use the command pipe (|) symbol to pass results from one PowerShell command into another one. E.G. I can pipe the results from Get-XAApplication report into Select-Object so that I only see the specific information I want from the XAApplication-Report command.
[code lang=”powershell”]
#
Get-XAApplicationReport | Select-Object BrowserName,CommandLineExecutable
#
[/code]
I can then pipe this again to the Export-CSV command so that I can save the data out of PowerShell
[code lang=”powershell”]
#
Get-XAApplicationReport | Select-Object BrowserName,CommandLineExecutable |
Export-CSV C:AppReport.csv
#
[/code]
Execution Policy
If you want to write your own scripts and run them on your XenApp servers then you will either need to sign your scripts or change the Execution Policy to allow unsigned scripts. This Microsoft blog post explains how to sign PowerShell scripts.If you want to allow unsigned scripts, run the following command on the server console
[code lang=”powershell”]
#
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
#
[/code]
Other PowerShell Resources
There is so much about PowerShell available on the internet, these are just a few of them.
XenApp Rolling Reboot Script for Zero downtime reboots
https://blog.itvce.com/?p=79
Carl Webster’s PowerShell script for documenting XenApp Infrastructure
https://carlwebster.com/where-to-get-copies-of-the-xenapp-farm-documentation-scripts/
I also have a few basic scripts in the Scripts and Downloads section