Saturday, December 12, 2009

PowerShell - Retrieving Useful Citrix Stats

I don't have much time this close to Christmas to get a real lengthy post up so i thought I would post up a PowerShell script that I created after reading some really great posts on Brandon Shells blog. All my script does is the following:

  • Lists active Citrix applications and how many users are using them.
  • Lists the Citrix Servers and how many sessions are active on each one.
  • Lists the first 15 users (this will display users that have more than one Citrix session open first).
I find all of these stats useful when I'm keeping an eye on my Citrix farm.

Here's the code:

#Count-CitrixSession.ps1
#count citrix sessions and other useful info

$farm = new-Object -com "MetaframeCOM.MetaframeFarm"
$farm.Initialize(1)

# displays a list of published apps and the number of users on each
write-host "Total users on each citrix application" -fore yellow
$farm.sessions | select UserName,AppName | group AppName | Sort Count -desc | select Count,Name | ft -auto
$livesessions = ($farm.Sessions).count
write-host "The number of current citrix sessions is" $livesessions -fore red

write-host " "

# list of citrix servers and total number of sessions on each one
write-host "Total sessions on each citrix server" -fore yellow
$farm.sessions | select ServerName,AppName | group ServerName | sort name | select Count,Name | ft -auto

write-host " "

# To see which users have more than one session open
write-host "First 15 Users with more than one citrix session" -fore yellow
$farm.sessions | select UserName,AppName | group UserName | Sort Count -desc | select Count,Name -first 15 | ft -auto


Before using this script you may need to download and install the free Metaframe Presentation Server SDK from the Citrix website.

+++

Share |

"make something then You never be lost"

wibiya widget