Monitor Citrix License Usage With PowerShell

WMI in Windows Server is a treasure trove of information and well worth investigating, particularly when needing to run reports against many servers. In addition it is possible for third-parties to make use of WMI and store their own information in there. This is true of a recent requirement I had to monitor Citrix Licensing.

Whilst it’s obviously critical to purchase enough licenses for Citrix that you need, its also important to not have too many lying around not in use, since you’ll be wasting money.  Given that Citrix Licensing is based on concurrency you may have different usage patterns at the time of day, month or year.

Contained within the WMI Namespace ROOT\CitrixLicensing is a class Citrix_GT_License_Pool. In this class you can find details for registered licenses and how many are in use. The PowerShell cmdlet Get-WMIObject can be used to retrieve this information. Once you have it you could save the report into a CSV file, write an entry to an event log or send an email alert.

The below example will generate an email alert when then level of licenses in use goes over 90%. The email will contain basic details of how many licenses are currently in use.

<# .SYNOPSIS Report on Citrix License Usage .DESCRIPTION Report on Citrix License Usage .NOTES Authors:Jonathan Medd .PARAMETER CitrixLicenseServer Name of Citrix License Server .EXAMPLE Get-CitrixLicenseUsage -CitrixLicenseServer Server01 #> param ( \[parameter(Mandatory=$True,HelpMessage='Name of Citrix License Server')\] $CitrixLicenseServer )

\# Get Citrix Licensing Info from WMI $LicensePool = Get-WmiObject -class "Citrix\_GT\_License\_Pool" -Namespace "ROOT\\CitrixLicensing" -ComputerName $LicenseServer

\# Calculate licenses in use, total number of licenses and percentage currently in use $InUseNum = ($LicensePool | Measure-Object -Property InUseCount -sum).Sum $InstalledLicNum = ($LicensePool | Measure-Object -Property Count -sum).Sum $PercentageNum = \[math\]::round(($InUseNum/$InstalledLicNum)\*100,2)

\# Check the usage and send an email if over 90% if ($PercentageNum -lt 90) { } else { Send-MailMessage -To "[email protected]" -Subject "Citrix License Server Statistics For $CitrixLicenseServer" -Body "The below is the current status of the license server:\`n\`nInstalled Licences: $InstalledLicNum\`n\`nLicences In Use: $InUseNum\`n\`nPercentage: $PercentageNum%" -SmtpServer "smtpserver" -From "[email protected]" }