Tuesday, December 23, 2008

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.

Happy Holidays.

3 comments:

Anonymous said...

Not familiar with powerschell/mfcom

can this script be made to pull active as well as disconnected user info?

SynJunkie said...

Yes, this will query active users

Anonymous said...

$farm.sessions | select UserName,AppName | group UserName | Sort Count -desc | select Count, Name | Where-Object -FilterScript {$_.Count -gt 1} | ft -auto

If you change to that line, it will show all users with more than 1 session.