When I am health-checking or otherwise working in customerCitrix Virtual Apps and Desktops (CVAD) environments, I often use a PowerShell prompt and scripts to get the information I need and to perform tasks as I find it easier and quicker than using the various Citrix, or Microsoft, consoles for many operations.
In this post I will show you some of the commands, with parameters, that I use. The beauty of being proficient in PowerShell is that once you know how to filter, sort, display, etc with one type of object, returned by a PowerShell function or cmdlet, you can use the exact same knowledge to work with practically every other cmdlet from every other provider – well worth the sometimes steep learning curve!
In a CVAD environment we need the CVAD PowerShell cmdlets which are installed when Citrix Studio is installed although the msi installer files for them exist separately on the CVAD installation ISO so can be installed without Studio if desired.
I typically will have these installed on a “jump box” rather than using a delivery controller directly as that risks resource and stability issues (“oops, I rebooted the wrong machine” said no admin ever).
The easiest way to get the cmdlets you need is to just load everything although in a script I would recommend just adding the specific modules that you need (Get-Command will tell you what module a specified cmdlet resides in). In 1912 LTSR and above we run:
Import-Module -Name Citrix*
(or ipmo Citrix* for short where “ipmo” is the alias for “Import-Module”)
For earlier releases, where modules weren’t available, we run:
Add-PSSnapin -Name Citrix*
(or asnp Citrix* for short where “asnp” is the alias for “Add-PSSnapin”)
Note that if you are using Citrix Cloud, you need to use the Remote PowerShell SDK rather than Studio or the MSIs from the CVAD ISO.
One other thing to bear in mind if you’re not running this on a delivery controller, which I don’t recommend, is that you will need to pass -AdminAddress to the CVAD cmdlets together with the name/address of a delivery controller.
If using Citrix Cloud, the argument to -AdminAddress needs to be an on-premises cloud connector. I’m sure I’ve read somewhere in Citrix documentation that you only need to specify it once, but I’ve had problems with that so specify it for every CVAD cmdlet called, albeit usually via a hash table using PowerShell’s “splatting” feature so if I need to change it, or add an extra common parameter, I can do it in one place.
Fig. 1: Using -MaxRecordCount you can return more than the default 250 records
In some of the examples I use a variable of type string called ‘ddc’ which I have set as one of the delivery controllers so that I don’t reveal its name in the screenshots.
Here are some useful queries, noting that most begin with Get-Broker. To see what cmdlets are available, you can run this
Pipe the above through Out-GridView (alias ogv) to see in a handy, filterable and sortable, table.
Alternatively, enter Get-Broker and either hit the tab key to cycle through the list of commands or hit ctrl+space to bring a cursor selectable list up on screen as seen in Figure 2.
Fig. 2: Get-Broker brings up a cursor selectable list of all available cmdlets
You can also use the Get-Help cmdlet on them, with optional -ShowWindow or -OnLine parameters, to get more detail and to see examples of their usage.
Q1. How many sessions are there in total, including connected and disconnected?
Note that here we get all active sessions, as in not disconnected, and store them in a variable. This way, we can perform analysis of this data without having to fetch it repeatedly, although the downside is that the data does not auto refresh.
Also note, that we filter in the cmdlet itself (-SessionState), where possible, rather than piping through Where-Object (alias where or ?) as that is faster because using Where-Object retrieves the entire result set and then filters it (figure 4).
Fig. 4: With the command described above, you receive a list of all active sessions
Fig. 8: Delivery group statistics in Citrix Studio
Note the use of -PassThru to Out-GridView so the selected items in the grid view – when “OK” is pressed – will be made available where the cmdlet was called from.
Alternatively, they can be piped through Set-ClipBoard (alias scb) so that the data can be pasted into Notepad, an email, OneNote, change control notes, etc.
Fig. 9: You can paste the data into notepad via Set-ClipBoard
In most cases, we can pipe the results from the previous queries into cmdlets to take action. But please ensure that you know the implications/impact of the action you are performing and that you are only operating on selected sessions/users, machines, etc rather than say logging off all 5000+ current sessions rather than the one user having an issue!
One can also pipe the results of Get-BrokerMachine into Set-BrokerMachine.
You can even create custom Notification via Send-BrokerSessionMessage, as can be seen in figure 10.
Get-BrokerSession -MachineName GUYRLEECH\GLXA19PVS41 @commonCVADparameters | Send-BrokerSessionMessage -Title "Message from Guy Leech" -MessageStyle Critical -Text "Please logoff & back on as an urgent reboot is required"
Fig. 10: A custom popup notification created in PowerShell
Note that this will not prompt the users nor give them a grace period so ensure they are expecting their session to be logged off!