Sessionright

Citrix® Health Check PowerShell Script: A Free, Read-Only HTML Report

By Jay H.Published Updated 13 min read

Jay H. · Founder, Sessionright
Founder of Sessionright. Twenty years running Citrix, NetScaler, Citrix Cloud, NetScaler Console, Azure and Azure Virtual Desktop estates; writes the guides and reviews the platform's rules.

Script turned up something you don't like? Talk it through with a Sessionright engineer: 15 minutes, free.

Citrix gives you cmdlets, not a health check script. The Broker SDK can tell you whether every Delivery Controller is Active, which VDAs are powered on but unregistered and why, and who changed what last week, but you have to ask each question yourself. This guide gives you one read-only script that asks 15 of those questions and writes the answers to a single HTML report.

It works against an on-premises Citrix Virtual Apps and Desktops (CVAD) site and against Citrix DaaS. Every Citrix cmdlet in it comes from Citrix's SDK reference for CVAD 2603, and every one starts with Get-. Run it as a Read Only Administrator and the site itself refuses any change.

What the script checks

Each check is one question with a pass condition taken from the cmdlet's documented properties. "Row" is the matching row in the 45-point checklist.

# Check Cmdlet Flags when Runs on Row
1 Controllers not Active Get-BrokerController State isn't Active (valid values: Off, Transitioning, Active, Failed) (SDK) CVAD 1
2 Controller versions Get-BrokerController More than one ControllerVersion CVAD 1
3 FMA services not OK Get-BrokerServiceStatus and seven sibling *ServiceStatus cmdlets ServiceStatus isn't OK on any Controller (SDK) CVAD 2
4 Licensing state Get-BrokerController LicensingGraceState isn't NotActive, or LicensingServerState isn't OK or LasConnectionOK CVAD 25
5 Local Host Cache off Get-BrokerSite LocalHostCacheEnabled is false (SDK) CVAD 7
6 Delivery groups Get-BrokerDesktopGroup Disabled, in maintenance mode, or DesktopsFaulted above 0 (SDK) Both 5
7 Hypervisor connections Get-BrokerHypervisorConnection IsReady is false or FaultState isn't None (SDK) Both 6
8 Powered-on VDAs not registered Get-BrokerMachine RegistrationState isn't Registered and PowerState is On or Unmanaged Both 14
9 VDAs in the registration sin bin Get-BrokerMachine InRegistrationSinBin is true Both 14
10 VDAs in a fault state Get-BrokerMachine FaultState isn't None Both 15
11 VDAs in maintenance mode Get-BrokerMachine InMaintenanceMode is true Both 16
12 VDA versions Get-BrokerMachine Info: machine count per AgentVersion Both 17
13 Configuration changes Get-LogHighLevelOperation Info: every change in the last 7 days (SDK) Both 42
14 Failed configuration changes Get-LogHighLevelOperation IsSuccessful is false Both 42
15 Administrators Get-AdminAdministrator Info: every admin and whether it's enabled (SDK) Both 42

Check 8 includes PowerState Unmanaged so machines Citrix doesn't power-manage aren't skipped. StoreFront, NetScaler® Gateway, certificates, FSLogix and SQL backups are out of scope; the checklist covers them.

Checks 8 to 12 use Get-BrokerMachine. Citrix has deprecated it in favour of Get-BrokerMachineV2, introduced in CVAD 2511, but it still works until Citrix removes it (deprecations). If you switch, pass -Property with the columns each check reads, because Get-BrokerMachineV2 returns only a default subset of properties (SDK).

Prerequisites

On Citrix Virtual Apps and Desktops

  1. Use a Delivery Controller or a machine with Studio installed. The SDK "installs automatically as a PowerShell module when you install a Delivery Controller or Studio" (Citrix docs). If you installed it as a snap-in instead, the script runs Citrix's own Add-PSSnapin Citrix.*.Admin.V*.
  2. Open Windows PowerShell (powershell.exe), not PowerShell 7. The same page says the product supports PowerShell 3 through 5.
  3. To query a Controller from a jump host, pass -AdminAddress, one of the common Citrix parameters the SDK cmdlets support (SDK).

On Citrix DaaS (Remote PowerShell SDK)

  1. Pick a domain-joined machine inside the resource location. Citrix says: "Do not install the Remote PowerShell SDK on a Citrix Cloud Connector machine." If you also run CVAD, don't install it on an on-premises Delivery Controller or a server running Citrix Studio (Citrix docs).
  2. Install Microsoft Edge WebView2 and make sure PowerShell 3.0 to 7.0 is available. The installer adds .NET Framework 4.8 if it's missing. Remove the CVAD SDK first if it's installed.
  3. Authenticate with Get-XdAuthentication, which prompts for credentials once per PowerShell session. Access "remains valid in the current PowerShell session for 24 hours". For unattended runs, Set-XdCredentials creates a default profile from a Secure Client made in the Citrix Cloud console.
  4. Run the script with -Mode DaaS. The cmdlets "disabled in remote operations" include Get-BrokerController, Get-BrokerDBConnection and Test-BrokerDBConnection. In DaaS the Controllers sit in the Citrix-managed control plane, so the script skips checks 1 to 5.

A read-only Citrix administrator

Citrix says you "must run the shell or script using an identity that has Citrix administration rights", and recommends dedicated Citrix administrators over the local Administrators group (Citrix docs). Use the built-in Read Only Administrator role. It exists on both CVAD and DaaS (DaaS docs). The role is scoped, though. A Read Only Administrator scoped to London can't see New York delivery groups, so give the account a scope that covers everything you want in the report.

Execution policy

RemoteSigned is the default on Windows clients and servers and blocks unsigned scripts downloaded from the internet until you run Unblock-File. The execution policy "isn't a security boundary" (Microsoft Learn); the Citrix role is what keeps this script read-only.

Running it

  1. Save the script below as Invoke-CitrixHealthCheck.ps1 and read it end to end before you run it.
  2. If you downloaded it, run Unblock-File .\Invoke-CitrixHealthCheck.ps1.
  3. On CVAD, run .\Invoke-CitrixHealthCheck.ps1 -AdminAddress ddc01.corp.example. On DaaS, run Get-XdAuthentication first, then .\Invoke-CitrixHealthCheck.ps1 -Mode DaaS.
  4. Open the HTML file named in the last line of output.
<#
  Invoke-CitrixHealthCheck.ps1
  Read-only health check for Citrix Virtual Apps and Desktops and Citrix DaaS.
  Calls Get-* cmdlets only and writes one HTML file. Run as a Read Only Administrator.
#>
param(
  [ValidateSet('Cvad', 'DaaS')] [string] $Mode = 'Cvad',
  [string] $AdminAddress = 'localhost',
  [string] $OutFile = (Join-Path $PWD ('CitrixHealth-{0:yyyyMMdd-HHmm}.html' -f (Get-Date))),
  [int] $ChangeDays = 7,
  [int] $MaxRecords = 100000
)
$ErrorActionPreference = 'Stop'
if (-not (Get-Command Get-BrokerMachine -ErrorAction SilentlyContinue)) {
  Add-PSSnapin Citrix.*.Admin.V*
}

$c = @{}
if ($Mode -eq 'Cvad') { $c.AdminAddress = $AdminAddress }
$summary = New-Object System.Collections.ArrayList
$detail  = New-Object System.Collections.ArrayList
$machines = $null

function Get-HcMachine {
  if ($null -eq $script:machines) {
    $script:machines = @(Get-BrokerMachine @c -MaxRecordCount $MaxRecords)
  }
  $script:machines
}

function Invoke-Check {
  param([string] $Name, [string] $Scope, [string[]] $Columns, [switch] $Info, [scriptblock] $Test)
  if ($Scope -eq 'CVAD' -and $Mode -ne 'Cvad') { return }
  try {
    $rows = @(& $Test | Where-Object { $_ })
    $status = if ($Info) { 'INFO' } elseif ($rows.Count) { 'FAIL' } else { 'PASS' }
  } catch {
    $rows = @()
    $status = 'ERROR: ' + $_.Exception.Message
  }
  [void]$summary.Add([pscustomobject]@{ Check = $Name; Scope = $Scope; Status = $status; Items = $rows.Count })
  if ($rows.Count) {
    [void]$detail.Add(($rows | Select-Object -Property $Columns |
      ConvertTo-Html -Fragment -PreContent "<h2>$Name</h2>" | Out-String))
  }
}

$fma = 'Get-BrokerServiceStatus', 'Get-ConfigServiceStatus', 'Get-LogServiceStatus', 'Get-MonitorServiceStatus',
       'Get-HypServiceStatus', 'Get-ProvServiceStatus', 'Get-AcctServiceStatus', 'Get-AdminServiceStatus'
$vdaCols = 'DNSName', 'CatalogName', 'DesktopGroupName', 'PowerState', 'RegistrationState',
           'FaultState', 'LastDeregistrationReason', 'LastDeregistrationTime', 'AgentVersion'
$changeFilter = 'StartTime -ge "{0:yyyy-MM-dd HH:mm:ss}"' -f (Get-Date).AddDays(-$ChangeDays)

Invoke-Check -Name 'Controllers not Active' -Scope CVAD -Columns DNSName, State, ControllerVersion, LastActivityTime -Test {
  Get-BrokerController @c | Where-Object { $_.State -ne 'Active' }
}
Invoke-Check -Name 'Controller versions' -Scope CVAD -Columns ControllerVersion, Count, Controllers -Test {
  $g = @(Get-BrokerController @c | Group-Object ControllerVersion)
  if ($g.Count -gt 1) {
    $g | Select-Object @{ n = 'ControllerVersion'; e = { $_.Name } }, Count,
      @{ n = 'Controllers'; e = { ($_.Group | ForEach-Object { $_.DNSName }) -join ', ' } }
  }
}
Invoke-Check -Name 'FMA services not OK' -Scope CVAD -Columns Controller, Service, ServiceStatus -Test {
  foreach ($ddc in (Get-BrokerController @c | ForEach-Object { $_.DNSName })) {
    foreach ($cmd in $fma) {
      try { $st = (& $cmd -AdminAddress $ddc).ServiceStatus } catch { $st = 'Unreachable: ' + $_.Exception.Message }
      if ($st -ne 'OK') { [pscustomobject]@{ Controller = $ddc; Service = $cmd; ServiceStatus = $st } }
    }
  }
}
Invoke-Check -Name 'Licensing state' -Scope CVAD -Columns DNSName, LicensingServerState, LicensingGraceState -Test {
  Get-BrokerController @c | Where-Object {
    $_.LicensingGraceState -ne 'NotActive' -or $_.LicensingServerState -notin 'OK', 'LasConnectionOK' }
}
Invoke-Check -Name 'Local Host Cache off' -Scope CVAD -Columns Name, LocalHostCacheEnabled -Test {
  Get-BrokerSite @c | Where-Object { -not $_.LocalHostCacheEnabled }
}
Invoke-Check -Name 'Delivery groups' -Scope Both -Columns Name, Enabled, InMaintenanceMode, TotalDesktops, DesktopsAvailable, DesktopsFaulted, Sessions -Test {
  Get-BrokerDesktopGroup @c -MaxRecordCount $MaxRecords |
    Where-Object { -not $_.Enabled -or $_.InMaintenanceMode -or $_.DesktopsFaulted -gt 0 }
}
Invoke-Check -Name 'Hypervisor connections' -Scope Both -Columns Name, State, IsReady, FaultState, FaultReason -Test {
  Get-BrokerHypervisorConnection @c | Where-Object { -not $_.IsReady -or $_.FaultState -ne 'None' }
}
Invoke-Check -Name 'Powered-on VDAs not registered' -Scope Both -Columns $vdaCols -Test {
  Get-HcMachine | Where-Object { $_.RegistrationState -ne 'Registered' -and $_.PowerState -in 'On', 'Unmanaged' }
}
Invoke-Check -Name 'VDAs in the registration sin bin' -Scope Both -Columns $vdaCols -Test {
  Get-HcMachine | Where-Object { $_.InRegistrationSinBin }
}
Invoke-Check -Name 'VDAs in a fault state' -Scope Both -Columns $vdaCols -Test {
  Get-HcMachine | Where-Object { $_.FaultState -ne 'None' }
}
Invoke-Check -Name 'VDAs in maintenance mode' -Scope Both -Columns DNSName, DesktopGroupName, PowerState, SummaryState -Test {
  Get-HcMachine | Where-Object { $_.InMaintenanceMode }
}
Invoke-Check -Name 'VDA versions' -Scope Both -Info -Columns AgentVersion, Count -Test {
  Get-HcMachine | Group-Object AgentVersion | Sort-Object Count -Descending |
    Select-Object @{ n = 'AgentVersion'; e = { $_.Name } }, Count
}
Invoke-Check -Name "Configuration changes, last $ChangeDays days" -Scope Both -Info -Columns StartTime, User, Text, IsSuccessful -Test {
  Get-LogHighLevelOperation @c -OperationType ConfigurationChange -Filter $changeFilter -MaxRecordCount $MaxRecords
}
Invoke-Check -Name "Failed configuration changes, last $ChangeDays days" -Scope Both -Columns StartTime, User, Text -Test {
  Get-LogHighLevelOperation @c -OperationType ConfigurationChange -Filter $changeFilter -MaxRecordCount $MaxRecords |
    Where-Object { $_.IsSuccessful -eq $false }
}
Invoke-Check -Name 'Administrators' -Scope Both -Info -Columns Name, Enabled -Test {
  Get-AdminAdministrator @c -MaxRecordCount $MaxRecords
}

$style = @'
<style>
body { font-family: Segoe UI, Arial, sans-serif; font-size: 13px; }
table { border-collapse: collapse; margin-bottom: 16px; }
th, td { border: 1px solid #ccc; padding: 4px 8px; text-align: left; }
th { background: #f0f0f0; }
.pass { background: #d4edda; } .fail { background: #f8d7da; } .error { background: #fff3cd; }
</style>
'@
$title = 'Citrix health check ({0}, {1:yyyy-MM-dd HH:mm})' -f $Mode, (Get-Date)
$top = $summary | ConvertTo-Html -Fragment -PreContent "<h1>$title</h1>" | Out-String
$top = $top -replace '<td>PASS</td>', '<td class="pass">PASS</td>' `
            -replace '<td>FAIL</td>', '<td class="fail">FAIL</td>' `
            -replace '<td>ERROR', '<td class="error">ERROR'
ConvertTo-Html -Head "<title>$title</title>$style" -Body (@($top) + $detail) |
  Out-File -FilePath $OutFile -Encoding utf8
Write-Output "Report written to $OutFile"
if ($summary | Where-Object { $_.Status -ne 'PASS' -and $_.Status -ne 'INFO' }) { exit 1 }

The parameters you'll actually change:

Parameter Default Use it to
-Mode Cvad Switch to DaaS for the Remote PowerShell SDK
-AdminAddress localhost Point at a Controller from a jump host (CVAD only)
-ChangeDays 7 Widen or narrow the configuration change window
-MaxRecords 100000 Raise the record cap on very large sites
-OutFile CitrixHealth-<date>.html in the current folder Write to a share or ticket folder

The time filter uses the -Filter form from Citrix's own example, StartTime -ge "<date>" (SDK).

Reading the HTML report

The page opens with a summary table: one row per check, with Check, Scope, Status and Items. Detail tables follow, only for checks that returned rows.

Status Meaning What to do
PASS The check ran and found nothing Nothing
FAIL The check found rows that need attention Read its detail table
INFO Inventory for review, never a failure Compare with last week's report
ERROR: <message> The cmdlet threw Usually a permission, scope or SDK problem; fix it before trusting the report

How to read the detail tables:

  • FMA services. PendingFailure means connectivity to the database "has been lost", possibly a transitory network error. Failed means it's been lost "for an extended period of time". DBNewerVersionThanService or DBOlderVersionThanService means the service and its database schema don't match, and Citrix's fix is to upgrade whichever is older (SDK). An Unreachable row means the script couldn't query that Controller at all.
  • Unregistered VDAs. Sort by LastDeregistrationReason. Citrix documents values such as AgentNotContactable, AgentWrongActiveDirectoryOU, IncompatibleVersion and FunctionalLevelTooLowForCatalog (SDK). Our VDA unregistered guide works through the common ones.
  • Sin bin. A machine lands there when "registration attempts were repeatedly failing". That usually means its configuration is wrong. After you fix it, "it may take several minutes for the machine to exit the sin bin".
  • Fault states. FailedToStart means the last power-on failed, StuckOnBoot means it doesn't seem to have booted, and MaxCapacity means it reports itself full. A delivery group's DesktopsFaulted counts machines "whose FaultState is not None".
  • Licensing. Any LicensingGraceState other than NotActive (the documented values are InOutOfBoxGracePeriod, InSupplementalGracePeriod, InEmergencyGracePeriod and GracePeriodExpired) means a Controller is in or past a grace period (SDK).
  • Configuration changes. IsSuccessful is empty while an operation is still running or if it never completed (SDK). The failed-changes check matches only an explicit false, so look at the empty rows in the info table too.

Every detail table has a fixed column list. ConvertTo-Html builds a table from the first object's properties and drops any extra properties on later objects (Microsoft Learn). Selecting the columns first keeps every row consistent.

Extending it

Each check is one Invoke-Check call: a name, a scope, the columns to show and a script block that returns the rows needing attention. For example, Get-BrokerMachine exposes ImageOutOfDate, which "denotes if the VM image for a hosted machine is out of date" (SDK):

Invoke-Check -Name 'VDAs on an out-of-date image' -Scope Both -Columns $vdaCols -Test {
  Get-HcMachine | Where-Object { $_.ImageOutOfDate }
}

Three rules keep the script safe to hand to anyone:

  1. Only Get- cmdlets in the default run. Citrix's own infrastructure tests run with Start-EnvTestTask -TestSuiteId Infrastructure (SDK). That starts a task, so put it behind its own switch rather than in the default run.
  2. Keep the Read Only Administrator role. If someone adds a Set- line by mistake, the role can't change anything, so the change fails instead of reaching the site.
  3. Keep a machine-readable copy. ConvertTo-Html has siblings, ConvertTo-Csv and ConvertTo-Json. Writing $summary | ConvertTo-Json next to the HTML lets you diff this week's run against last week's.

Limits of scripts vs continuous checks

A script is a snapshot. Know what it can't do:

  • It only sees the moment it ran. A VDA that deregisters an hour later isn't in the report. Citrix's Cloud Health Check has a scheduler, but it "can only schedule one task at a time on a domain-joined machine", and its runs are periodic, not continuous (Citrix docs).
  • Not every health tool is read-only. Cloud Health Check's Automatic fix can "automatically detect and fix certain issues" and is enabled by default. Decide which tools may write before you schedule them.
  • Unattended DaaS runs need a stored credential. A scheduled task can't answer the prompt, so it needs a Secure Client profile from Set-XdCredentials. Protect that secret like any service account.
  • Scope hides objects. A narrowly scoped Read Only Administrator gets a clean report that is also incomplete.
  • Coverage is partial. Eleven of 45 checklist rows is a weekly baseline, not a full health check.
  • There is no history unless you keep the JSON and compare runs yourself.

FAQ

Is there an official Citrix health check PowerShell script?

Not as a single report script. Citrix ships the SDK cmdlets this script is built on, plus tools such as Cloud Health Check for VDAs, StoreFront and Profile Management on DaaS. The script above combines the cmdlets into one HTML report.

How do I run a Citrix Cloud health check PowerShell script?

Install the Remote PowerShell SDK on a domain-joined machine in your resource location, not on a Cloud Connector. Then run Get-XdAuthentication and .\Invoke-CitrixHealthCheck.ps1 -Mode DaaS. Controller and database checks are skipped because Citrix disables those cmdlets remotely.

Can this script change anything in my Citrix site?

No. It calls only Get-* cmdlets and writes one local HTML file. Run it as a Read Only Administrator, a role that Citrix says "cannot change anything", and the site enforces that even if someone edits the script.

How do I create a Citrix health check report in HTML with PowerShell?

Pipe each result through ConvertTo-Html -Fragment with a -PreContent heading, then pass the fragments to ConvertTo-Html -Head <style> -Body <fragments> and Out-File, as the last block of the script does.

Does the Citrix PowerShell SDK work with PowerShell 7?

For on-premises CVAD, Citrix states support for PowerShell 3 through 5, so use Windows PowerShell. The DaaS Remote PowerShell SDK lists PowerShell 3.0 to 7.0 in its requirements.

Why does Get-BrokerController fail on Citrix DaaS?

Citrix disables it in remote operations, together with the *DBConnection cmdlets, "to maintain the integrity and security of the Citrix Cloud control plane". In DaaS, check what you run: Cloud Connectors and VDAs.

Want a second pair of eyes?

A script answers the questions it was written to ask. If you want more than these 15 questions answered, the Sessionright assessment is a read-only review of your Citrix environment. Sessionright for Citrix is read-only by default too. Every change it proposes waits for your approval and is logged (security model). If you would rather talk it through, book a 15-minute call: no install, no sales deck.

Sources

Want these checks and evidence reviewed with an engineer?

Sessionright assesses Citrix sites and NetScaler Gateway with read-only access and attaches the evidence to its findings. Citrix assessment is read-only today; a Sessionright engineer guides manual work. Nightpatch provides NetScaler upgrade plans. 90-day free Operator pilot, then 50% off year 1; list price at signing held to month 24. Engineer-led assessments are 50% off for design partners. It has run against simulated estates and Sessionright's own Azure lab tenant so far. Outside the program the onboarding assessment is $5,500, one site, up to 1,000 users, up to 2 HA pairs.

Not ready for that? Talk to a Sessionright engineer: 15 minutes, free, and you leave with a next step.

Get this script as a file

Download the read-only script pack, with the source guides and instructions for each file.

Or get the next guide by email. One email per new guide, no marketing list.

New Sessionright guides by email. No marketing drip; unsubscribe in one click.

Related guides

Citrix and NetScaler are trademarks of Citrix Systems, Inc. and/or its affiliates. Azure is a trademark of the Microsoft group of companies. Sessionright is not affiliated with or endorsed by Cloud Software Group, Citrix or Microsoft.