-
Counting the Number of Sessions Per Citrix Server
Posted on March 4th, 2009 5 commentsWhilst monitoring some newly provisioned Citrix servers running on VMware hosts today, I soon became very bored with manually checking how many sessions were on each Citrix VM as the load on each one increased, whilst trying to get it to the optimum level.
I knew it was possible to use Powershell to connect with Citrix servers, but had never really looked into it before. Not surprisingly it turned out to be very straightforward.
By using some technology known as MFCom we can connect with the Citrix farm and get some cool information out.
In the below example we create a new com object using MFCom, then initialise the connection. We are then able to access some methods and properties of that object. In this case we are looking at the Sessions property, we group all of the results by ServerName and then produce some output with the name and number of sessions on that Citrix box.
$farm = New-Object -com "MetaframeCOM.MetaframeFarm"$farm.Initialize(1)$farm.Sessions | Group-Object ServerName | Sort-Object name | Format-Table Name,Count -auto
which will give you something like:
Name Count
CitrixServer01 38
CitrixServer02 45
CitrixServer03 41This would return all of the servers in the farm. In this particular instance I only wanted a particular selection of servers, so I stored them in a text file, got PS to read that file and then filter the query by only looking at servers in that list.
$servers = Get-Content c:\scripts\servers.txt $farm = New-Object -com "MetaframeCOM.MetaframeFarm"$farm.Initialize(1)$farm.sessions | Where-Object {$servers -contains $_.ServerName} | Group-Object ServerName | Sort-Object name | Format-Table Name,Count -auto
Once again Powershell very easily gets rid of a really dull manual task.
If you wish to take this a step further check out Powershell MVP Brandon Shell’s blog where he has loads of Powershell / Citrix examples.
http://bsonposh.com/archives/tag/citrix
5 responses to “Counting the Number of Sessions Per Citrix Server”

-
Hi Jonathan
My name is Vishal Ganeriwala and I manage the Citrix Developer Network Program. This is a great blog post. You can find more examples on
http://community.citrix.com/cdn/xa/codesharePlease feel free to contact me if you have any questions regarding MFCOM APIs.
-
Jonathan Medd March 5th, 2009 at 19:38
Thanks, will check it out.
-
Eduardo October 20th, 2010 at 15:45
Hello Jonathan congratulations for your awsome blog, may be you culd help me cose Im trying to do this same for Citrix session but with a particular diferences. Im runing powershell 2 from a server with XenApp 6 and im trying to get the ICA sessions for a farm with XenApp 4.5, Could you please provie me some lights to try to solve this? Thanks In Advance
-
Eduardo October 21st, 2010 at 15:57
Thanks for your quick response, I’m afraid that you’re right about this and I will need to have installed powershell on the farm with 4.5 just had this doubt because even now I run scripts to check services and disk space from this server with XenApp 6 to all servers with 4.5, but that is more related to windows that citrix
Leave a reply
-









vishal ganeriwla March 5th, 2009 at 17:00