vda

Citrix VDA uptimes

· 1 min read
Citrix VDA uptimes
Photo by Markus Spiske / Unsplash

Today I needed to extract the uptime of a Citrix Virtual Apps and Desktops site and gather the data to be able to format it present it in a report form, HTML or email.

Here is the Powershell code I wrote to do so

Add-PSSnapin Citrix*
$CtxDelCtrl = "deliverycontrollerFQDN:Port"

foreach ($server in (Get-BrokerMachine  -AdminAddress $CtxDelCtrl - -Skip 0 | Select-Object HostedMachineName )) {
$lastboottime = (Get-WMIObject -Class Win32_OperatingSystem -ComputerName $server.HostedMachineName -ErrorAction SilentlyContinue).LastBootUpTime
If($lastboottime){
$sysuptime = (Get-Date) - [System.Management.ManagementDateTimeconverter]::ToDateTime($lastboottime)
$uptime = "   UPTIME           :    $($sysuptime.days) Days, $($sysuptime.hours) Hours, $($sysuptime.minutes) Minutes, $($sysuptime.seconds) Seconds"
} Else {
$uptime = "   UPTIME           : Unable to determine for host $server.HostedMachineName"
}
Write-Host $server.HostedMachineName $uptime
}

and if you need to filter by Delivery Group and / or Session type you can add

Filter "((SessionSupport -eq `"SingleSession`" -and DesktopGroupName -eq `"DesktopGroupName`"))"

The full script with the filter :

Add-PSSnapin Citrix*
 
$CtxDelCtrl = "deliverycontrollerFQDN:Port"
 
 
foreach ($server in (Get-BrokerMachine  -AdminAddress $CtxDelCtrl -Filter "((SessionSupport -eq `"SingleSession`" -and DesktopGroupName -eq `"DesktopGroupName`"))" -Skip 0 | Select-Object HostedMachineName )) {
 
 
$lastboottime = (Get-WMIObject -Class Win32_OperatingSystem -ComputerName $server.HostedMachineName -ErrorAction SilentlyContinue).LastBootUpTime
If($lastboottime){
    $sysuptime = (Get-Date) - [System.Management.ManagementDateTimeconverter]::ToDateTime($lastboottime)
    $uptime = "   UPTIME           :    $($sysuptime.days) Days, $($sysuptime.hours) Hours, $($sysuptime.minutes) Minutes, $($sysuptime.seconds) Seconds" 
} Else { 
    $uptime = "   UPTIME           : Unable to determine for host $server.HostedMachineName" 
 
} 
 Write-Host $server.HostedMachineName $uptime 
 
 
}

The only downside for now is the uptime for Linux VDA is not working