Saturday, August 25, 2007

[vbscript] Finding Dead Citrix Servers...

One of the things I hate most of all is finding a Citrix server that sits all day dead... that is it's up, it's pingable, but for some strange reason no one is connected to it. Sometimes the users know something is up with a well placed "Cannot connect to the Citrix MetaFrame server. There is no Citrix Metaframe server configured on the specified address" error or sometimes not (which I notice is a majority of the times), most forms of proactive monitoring seems to be futile - sometimes you can RDP to the server, sometimes not - very frustrating.

So I have a little script I now run every morning to just see where my servers are at - unfortunatly it requres users to be actually in for the day, so it's not proactive in anyway. But if you built in enough servers to handle load, it makes a great way to find a dead server somewhere and fix it.

You will need to have the Citrix MPSSDK installed and MFREG ran so the PC you run this from can run the script (also it can run from any Citrix server by default).

<job id="FindDeadCitrixServers">
File: FindDeadCitrixServers.wsf
Description: Find Dead Citrix Servers in a given farm
Requirements: WSH 5.5+, Citrix SDK installed and MFREG connected to your farm.
Author: DH Collier -
Disclaimer: Use of this script is done at your own risk, what happens as a result is your own doing - it's provided for educational purposes only.
Find Dead Citrix Servers in the Farm.
CScript //nologo FindDeadCitrixServers.wsf
<reference object="MetaFrameCOM.MetaFrameApplication"/>
<reference object="MetaFrameCOM.MetaFrameServer"/>
<reference object="MetaFrameCOM.MetaFrameFarm"/>
<script language="VBScript">
Dim theFarm, aAPP, aServer
WScript.Echo "FindDeadCitrixServers Script"
WScript.Echo ""

' Create MetaFrameFarm object
Set theFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
if Err.Number <> 0 Then
WScript.Echo "Can't create the MetaFrameFarm object"
WScript.Echo "(" & Err.Number & ") " & Err.Description
WScript.Echo ""
WScript.Quit Err.Number
End if

' Initialize the farm object.
if Err.Number <> 0 Then
WScript.Echo "Can't Initialize the MetaFrameFarm object"
WScript.Echo "(" & Err.Number & ") " & Err.Description
WScript.Echo ""
WScript.Quit Err.Number
End if

' Am I a Citrix Administrator?
if theFarm.WinFarmObject.IsCitrixAdministrator = 0 then
WScript.Echo "You lack the Citrix Administrator Rights"
WScript.Echo ""
WScript.Quit 0
End If

' What Farm is this?
WScript.Echo "MetaFrame Farm Name: " & theFarm.FarmName
WScript.Echo ""

' Display all servers in the farm with no sessions
Set aServer = CreateObject("MetaFrameCOM.MetaFrameServer")
Set aAPP = CreateObject("MetaFrameCOM.MetaFrameApplication")

For Each aServer In theFarm.Servers
If aServer.SessionCount = 0 Then
WScript.Echo aserver.serverName & " has " & aserver.sessioncount & " Sessions."
For Each aAPP in aServer.Applications
WScript.Echo aAPP.DistinguishedName
WScript.Echo "-----------------"
End If


  1. Or "query session /server server01" will generate exactly same result.

  2. If you've got 50-100 servers in your farm then just run a psexec @yourserverlist.txt of the command mentionned above..