Citrix License Usage Monitoring using PowerShell


The below PowerShell script could be used to deliver automated emails on the Citrix License usage for Citrix Admins.

Where do you run this script from?

Citrix License Server

How do you run this?

The script could be saved as a file with an extension of .ps1

Also ensure that you have a folder called report_do_not_delete created in the C: drive on the license server. Also, make the relevant changes in the script marked in Red. Run the script as a scheduled task at a specific time to receive the license usage reports in your mailbox or run it manually from a PowerShell window in Admin mode

#Region Settings
#Your License Server
$CitrixLicenseServer = “yourlicenseservername”

#Do you want to report on licenses with 0 users?
$ShowUnusedLicenses = $true

#Toggle an alert above this percentage of licenses used
$UsageAlertThreshold = 0

#EndRegion Settings

#Region CollectData
#retrieve license information from the license server
$LicenseData = Get-WmiObject -class “Citrix_GT_License_Pool” -namespace “ROOT\CitrixLicensing” -ComputerName $CitrixLicenseServer

$usageReport = @()
$LicenseData | select-object pld -unique | foreach {
$CurrentLicenseInfo = “” | Select-Object License, Count, Usage, pctUsed, Alert
$CurrentLicenseInfo.License = $_.pld
$CurrentLicenseInfo.Count = ($LicenseData | where-object {$_.PLD -eq $CurrentLicenseInfo.License } | measure-object -property Count -sum).sum
$CurrentLicenseInfo.Usage = ($LicenseData | where-object {$_.PLD -eq $CurrentLicenseInfo.License } | measure-object -property InUseCount -sum).sum
$CurrentLicenseInfo.pctUsed = [Math]::Round($CurrentLicenseInfo.Usage / $CurrentLicenseInfo.Count * 100,2)
$CurrentLicenseInfo.Alert = ($CurrentLicenseInfo.pctUsed -gt $UsageAlertThreshold)
if ($ShowUnusedLicenses -and $CurrentLicenseInfo.Usage -eq 0) {
$usageReport += $CurrentLicenseInfo
} elseif ($CurrentLicenseInfo.Usage -ne 0) {
$usageReport += $CurrentLicenseInfo
}
}
#EndRegion CollectData
$usageReport |Select-Object @{name=’Date-time’;Expression={Get-Date} },License,Count,Usage,PctUsed,Alert|ft -AutoSize|Out-File -Append C:\report_do_not_delete\$(get-date -uformat “%Y-%m-%d”).txt
#$usageReport | Format-Table -AutoSize | out-file “C:\reports\usagereport.txt”

#mail
Send-MailMessage -From “sender@sample.com” -To “receiver@sample.com” -Subject “Citrix XenApp license usage – Daily Report” -Body “Citrix XenApp license usage – Daily Report” -SmtpServer “smtp.sample.com” -Attachments “C:\report_do_not_delete\$(get-date -uformat “%Y-%m-%d”).txt”


Find the database hosting XenDesktop Datastore


To find the database server hosting the XenDesktop database, log on to the Desktop Delivery Controller server

Open  PowerShell in admin mode and type the below commands

Capture23

The Server field gives you name of the database server, Initial Catalog is the database name and Integrated Security is the security type

Hope this helps.

 

Published Applications Report in Excel using Powershell


Here is a PowerShell script to extract the published applications in a CSV file. This script could be used for XenApp 6.0 or above farms . I do not own the script so please use this at your own risk.

 

# Create variables

asnp citrix*

$outpath = [environment]::getfolderpath(“mydocuments”) + “\XenApp_Published_App_Report.csv”

$xaapplist = get-xaapplication

$appreport=foreach ($application in $xaapplist)

{get-xaapplicationreport -BrowserName $application.BrowserName}

# pipe appreport variable and select required objects for output

$appreport |

select-object BrowserName,

applicationtype,

enabled,

@{n=’accounts’; e={$_.accounts}},@{n=’servernames’; e={$_.servernames}},@{n=’workergroupnames’; e={$_.workergroupnames}},folderpath,commandlineexecutable,clientfolder,

startmenufolder,

encryptionlevel,

encryptionrequired,

windowtype,

colordepth |

#Export results to a CSV

export-csv $outpath

 

The original source of the script could be found here