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]"
}


sdf

19 thoughts on “Monitor Citrix License Usage With PowerShell

  1. Hi,

    I want to generate citrix licence report inform of citrix licence,username,applicationused,usage prieod,used date.Iam useing MSaccess datastore.

    Please guide me on this requet

    Victor

  2. This script was working great for me, then I changed the default port License server runs on and now I get:
    CategoryInfo : InvalidArgument: (:) [Get-WmiObject], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetWmiObjectCommand

  3. The script is not working. Please suggest.

    Get-WmiObject :
    At C:\Users\mxk0204\desktop\test1.ps1:16 char:29
    + $LicensePool = Get-WmiObject <<<< -class "Citrix_GT_License_Pool" -Namespace "ROOT\CitrixLicensing" -ComputerName $C
    itrixLicenseServer
    + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    Attempted to divide by zero.
    At C:\Users\mxk0204\desktop\test1.ps1:21 char:43
    + $PercentageNum = [math]::round(($InUseNum/ <<<< $InstalledLicNum)*100,2)
    + CategoryInfo : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException

  4. I had the same issue with + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException.

    I needed to launch the Script in a “Run as Admin Powershell ” and then it was ok.

Comments are closed.