In this blog post, we will walk through a PowerShell script designed to monitor Citrix hosts and their maintenance mode status using PRTG. We will create ONE SENSOR for ALL Citrix hosts. Every single host will be displayed in a single channel.
Here’s the complete script:
<#
Author: S.Meier
V1.0
#>
param(
[string]$server
)
$citrixhosts = Invoke-Command -ComputerName $server{
Get-BrokerMachine | Select-Object MachineName, inMaintenanceMode}
$XMLOutput = "<prtg>"
foreach($citrixhost in $citrixhosts){
$channelname = $citrixhost.MachineName
$inMaintenanceMode = if ($citrixhost.inMaintenanceMode -eq $true) { 1 } else { 0 }
$XMLOutput += "
<result>
<channel>$channelname</channel>
<value>$inMaintenanceMode</value>
<unit>MaintenanceMode</unit>
</result>
"
}
$XMLOutput += @"
</prtg>
"@
Write-Host $XMLOutput
Let’s break down what this script does step by step.
- Parameter Definition:

This defines a parameter $server which will be the Citrix Delivery Controller. This is important, because you cant run the “Get-BrokerMachine” command on the PRTG Server.
2. Get Citrix host Maintenance Status

- ‘
Invoke-Command
‘ is used to run a command on the remote Citrix server specified by $server. 'Get-BrokerMachine'
retrieves information about the Citrix machines.- ‘
Select-Object
‘ filters the output to include onlyMachineName
andinMaintenanceMode
.
3. Initializin XML Output

PRTG expects sensor data to be provided in a specific XML format.
By initializing '$XMLOutput
‘ with ‘<prtg>
‘, we start creating a well-formed XML document that PRTG can understand.
This opening tag is essential because it tells PRTG that the following content contains the sensor data.
4. Adding channels for each host

This loop iterates through each Citrix host and constructs an XML result entry for each host.
'$channelname'
stores the name of the host.'$inMaintenanceMode'
is set to 1 if the host is in maintenance mode, otherwise 0.
Each result block will be added to the'$XMLOutput'
5. Closing the XML Output

This adds </prtg> to the end of the XML Output.
6. Outputting the XML Output

This command outputs the complete XML string to the console, which PRTG will read and process.