Last time, I talked about the contents of the XenApp 6 SDK, how to enable PowerShell to run the scripts included in the SDK, and what snap-ins we allow.

Within the PowerShell command prompt, run the following (note: this assumes you are running the SDK command prompt on a XenApp server, not on an SDK client):

Get-XAFarm

Assuming everything is working correctly, you will see output showing the farm name, the version of the XenApp software running on the local server, the type of Citrix administrator you are, and the total number of sessions running in your farm.

Let’s publish an application.  Everyone’s favorite application is notepad, right?

New-XAApplication ServerInstalled Notepad -CommandLineExecutable notepad.exe

If you are used to MFCOM, you are likely thinking to yourself: “that’s it?”  Yes, that is all you need.  When this command completes, you will have published an application whose binaries are located on the XenApp server(s), which is called Notepad, and whose command line is “notepad.exe”.  The icon will even be set automatically; something which was notoriously difficult to do properly in MFCOM.  You can verify the app exists by doing:

Get-XAApplication

One note: you’ll find that the newly created application is disabled.  This is because the application has no users or servers associated. If you want to fix this, do:

Set-XAApplication Notepad -Accounts <account> -Servers <server> -Enabled $true

Alternatively, you could have specified the Accounts and Servers parameters for the New-XAApplication cmdlet.

Now let’s see what sessions are running in the farm:

Get-XASession

Or perhaps, what sessions a user is running:

Get-XASession -Account <account>

Maybe you need to log off all of that user’s disconnected sessions:

Get-XASession -Account <account> | Where-Object { $_.State -eq "Disconnected" } | Stop-XASession

A common task that administrators write scripts for is to periodically query sessions and write them into a spreadsheet.  Other tools can then mine that data for trends.  PowerShell makes this trivial:

Get-XASession | Export-Csv <file>

This is just a taste of what’s available.  To see the whole list of Citrix commands, do:

Get-Command -Module Citrix*

This will list all of the commands in the Citrix.Common.Commands and Citrix.XenApp.Commands snap-ins.  For help on any of the commands, do:

Get-Help <command> -Detailed

Note that this only covers the part of the XenApp SDK which is implemented as PowerShell commands. Starting XenApp 6, farm, server, and user settings are stored in policies and do not have dedicated commands associated with them; they are configured using a PowerShell provider. In my next article, I’ll provide a primer on using the PowerShell provider to get and set the configuration of these policies.