Public/Set-CitrixMaintenanceMode.ps1
<#
.SYNOPSIS Enables or disables maintenance mode for a Citrix server. .DESCRIPTION This function enables or disables maintenance mode for a specified Citrix server. .PARAMETER AdminAddress Specifies the address of the Citrix Delivery Controller. .PARAMETER ComputerName Specifies the name of the Citrix server. .PARAMETER EnableMaintenanceMode Specifies whether to enable or disable maintenance mode. Accepted values are 'True' (enable) or 'False' (disable). .EXAMPLE Set-CitrixMaintenanceMode -AdminAddress "vdurctxddc001" -ComputerName "Server01" -EnableMaintenanceMode $true Enables maintenance mode for the Citrix server "Server01". .EXAMPLE Set-CitrixMaintenanceMode -AdminAddress "vdurctxddc001" -ComputerName "Server01" -EnableMaintenanceMode $false Disables maintenance mode for the Citrix server "Server01". .NOTES Requires Citrix PowerShell SDK and appropriate administrative credentials. #> Function Set-CitrixMaintenanceMode { [CmdletBinding()] param ( [Parameter(Mandatory = $true, Position = 0)] [string]$AdminAddress, [Parameter(Mandatory = $true, Position = 1)] [string]$ComputerName, [Parameter(Mandatory = $true, Position = 2)] [ValidateSet('True', 'False')] [boolean]$EnableMaintenanceMode ) try { $forceResetParams = @{ AdminAddress = $AdminAddress HostedMachineName = $ComputerName ErrorAction = 'Stop' } $MachineName = Get-BrokerMachine @forceResetParams if ($MachineName.InMaintenanceMode -eq $EnableMaintenanceMode) { if ($EnableMaintenanceMode) { "{0}" -f "MM ON" } else { "{0}" -f "MM OFF" } } else { Set-BrokerMachine -AdminAddress $AdminAddress -MachineName $MachineName.MachineName -InMaintenanceMode $EnableMaintenanceMode -ErrorAction Stop if ($EnableMaintenanceMode) { "{0}" -f "MM ON" } else { "{0}" -f "MM OFF" } } } catch { Write-Error $_.Exception.Message } } |