Sometimes you might need to find a server with no sessions.

If you have a larger environment, it’s a tedious task to go through every single server to find out. Here is a very quick script to ascertain servers with no sessions:

Let’s assume that we are only looking for servers that meet certain hostname requirements - such as servers with a ‘2’ in their name (or part of LMG2 as example)

add-pssnapin Citrix.*

$servers = Get-xaserver | where-object {$_.ServerName -like "\*P2\*"} | Select ServerName
$sessions = get-xasession | where-object {$_.ServerName -like "\*P2\*"} | select ServerName -Unique

Compare-object $servers.ServerName $sessions.ServerName

C:\Users\adm_root> Compare-Object $servers.ServerName $sessions.ServerName
InputObject SideIndicator
---------- -------------
CONTOSO-CTXXA-P245 (Left-hand side, or the $servers variable)

For some reason, the WP-code snapin doesn’t deal with “<=” at all? The above results indicate the server name “CONTOSO-CTXXA-P245” exists in the $servers variable, but not the $sesisons variable.