XenApplePie

Rolling Remove From Maintenance Script

I was seeing a longer time in upgrading from 2203CU2/CU3 to 2402 especially on VDI. For smaller vCPU amounts like 2 vs 4, the time was 15 minutes (4vCPU) versus nearly 30 minutes (2vCPU) to upgrade. To get machines back online faster, I modified another script I was using to identify what I needed to upgrade. The one issue you will have, is if you are running say 1912 and 2203 with different CUs, they would be below the targeted version in the script and not automatically removed from maintenance mode. You would have to manually remove those from maintenance mode.

Create a scheduled task, that has the appropriate rights and from a machine that can reach the devices, set it for a 5ish minute interval. In my case, I scheduled it from the same machine that was running the upgrade script. Another assumption is that you will need the PowerShell SDK for DaaS loaded on the machine as well. You will need to have a profile from that machine that has a connection profile named “default,” or change the ProfileName to match what yours happens to be.

You can get the $targetVersion information by upgrading one of your machines prior to the rest, which you should be doing and testing! Running the command Get-Brokermachine -HostedMachineName machinetobetested | Select-Object HostedMachineName, AgentVersion on the machine you updated will show the version.

asnp Citrix*

$report                        = @()
[System.Version]$targetVersion = "2402.0.100.629"
$getMachines                   = Get-BrokerMachine -MaxRecordCount 1000000

if($GLOBAL:XDSDKProxy -eq $null){

  Get-XDAuthentication -ProfileName "default"

}

foreach($machine in $getMachines){
  $line                   = "" | Select HostedMachineName, DNSName, AgentVersion, WillBeUpgraded, OperatingSystem, MaintenanceMode
  $testVersion            = $machine.AgentVersion
  
  $line.HostedMachineName = $machine.HostedMachineName
  $line.DNSName           = $machine.DNSName
  $line.AgentVersion      = $machine.AgentVersion
  $line.OperatingSystem   = $machine.OSType
  $line.MaintenanceMode   = $machine.InMaintenanceMode
  
  if([System.Version]$testVersion -ge [System.Version]($targetVersion)){

  $line.WillBeUpgraded    = "Current Version Or Newer"
  
  }
  
  if([System.Version]$testVersion -lt [System.Version]($targetVersion)){

  $line.WillBeUpgraded    = "Yes"
  
  }

  
  $report += $line


}


$removeFromMaintenanceMode = ($report | Where-Object {($_.WillBeUpgraded -notlike "Yes" -and $_.MaintenanceMode -eq "True")} | Select-Object HostedMachineName).HostedMachineName


foreach($remove in $removeFromMaintenanceMode){


Get-BrokerMachine -HostedMachineName "$remove" | Set-BrokerMachine -InMaintenanceMode $false


}

Exit mobile version