XenDesktop 7 Rolling Reboot Script

RebootScript_Progress_Report

The below script will perform a rolling reboot of all Servers in a Delivery Group.

It starts by placing servers with no sessions in Maintenance Mode and rebooting them one by one. All servers with active sessions are placed in Maintenance Mode to prevent new sessions. Any servers in Maintenance Mode when the script was started are ignored.

To prevent “breaking” your delivery group, if all servers have active sessions a percentage of servers are “held” for reboot later in the script. Otherwise users would be prevented from logging on. This is 20% by default but can be configured using the –HoldPercent parameter.

Servers in Maintenance Mode do not allow new connections but allow users to reconnect to their sessions.

Virtual Servers are rebooted using Hypervisor, physical are rebooted via Windows OS. By default the script uses the Hypervisor.

Once all servers with no sessions are rebooted, the servers with active sessions are checked every 5 minutes to see if all sessions have cleared down. Once all sessions are logged off the server is rebooted and taken out of Maintenance Mode.

If any servers were "held" for reboot they are rebooted at the end.

The script will end after all servers are rebooted or it times out (24 hours by default). All servers are taken out of maintenance mode after reboot and again at the end of the script to make sure.

Status reports are written to screen and file during various stages of the script. The status report will list: All servers, whether pending, hold, or rebooted, reboot time, whether in Maintenance Mode, and session count.

Below are some ideas I have to add to future versions.

  • Multiple Desktop Group support
  • Verification of Parameters. I.E Does desktopgroup exist?
  • Verification of HoldPercent to prevent using higher than 90%
  • Start Rebooting Hold Servers when 50% of existing servers rebooted rather than waiting to end of script
  • Option to force reboot if remaining sessions are RDP.
  • Timeout in case session hosts don't register with controller.
  • Abort script if more than x fail to reregister with controller
  • Rebooting servers in groups rather than one by one.
  • Signed script

Disclaimer: Use this script at your own risk. All scripts should be tested on non-Production environments first. I have not tested this script in a large environment yet. Once I have my new lab up and running I will have more capcity to test this.

Full list of syntax and help is available by typing Get-Help  XD7_Rolling_Reboot_V1.ps1

XenDesktop 7 Rolling Reboot with PS1 Extension (239 downloads) XenDesktop 7 Rolling Reboot Unsigned with txt Extension (154 downloads)

26 Responses

  1. Thanks Shaun! Great work:)

  2. […] Take a look… http://www.shaunritchie.co.uk/xendesktop-7-rolling-reboot-script […]

  3. Phil

    Just wondering if line 245 should check whether the server has been set to ‘Hold’ before either rebooting it or setting it to maintenance mode. If I’m reading the logical correctly this block will process all servers (either reboot or enable maintenance mode) regardless of their ‘Hold’ status, affecting the entire delivery group at one, not just a smaller percentage of servers.

    • Yeah, I might have missed something out there. In theory a hold server should not get rebooted as it would have active sessions and only servers with no sessions get rebooted but I am adding some logic. I will upload an updated script tomorrow.

      • Phil

        Hi Shaun, just running the updated script in a dev environment and noticed the following.
        In the section starting on line 297 wouldn’t it be better to run through all servers set to ‘hold’ and enable maintenance mode on them all. The way I see it at the moment is it enables maintenance mode on a single ‘hold’ server, waits for sessions to drain and reboots it before moving onto the next ‘hold’ server. Since these are the final batch of servers that the script will reboot it makes sense to apply maintenance mode on them all, then reboot whichever one drains first rather than trickling through them one by one, which could take a while if the site is huge.

        • I will check that and get back to you. I am making some updates to the script at the moment anyway.

  4. Manjunath S

    Hi Shaun,

    As there was small logic error in line 245 mentioned above, Have you uploaded the updated script? And also please let me know how to schedule this script in Windows task scheduler by passing the parameters?

    Thanks,
    Manju

    • I have made changes to the script. It is available for download now.

      If you create a scheduled task to run PowerShell.exe and in the Add arguments box you put something like

      -noexit -file C:ScriptsXD7_Rolling_Reboot_V1.1.ps1 -DeliveryGroup “Your Delivery Group” -HoldPercent 40

  5. Manjunath S

    Hi Shaun,

    Thanks, I tried to execute this script in test environment and getting below error message!!

    Cannot convert the “Citrix.Broker.Admin.SDK.Machine” value of type “Citrix.Broker.Admin.SDK.Machine” to type “System.Co
    llections.ArrayList”.
    At C:Reboot_TaskXD7_Rolling_Reboot_V1.1.ps1:143 char:39
    + [System.Collections.ArrayList]$Servers <<<< = Get-BrokerMachine -DesktopGroupName $DeliveryGroup | Where-Object {$_.
    InMaintenanceMode -ne "True"}
    + CategoryInfo : MetadataError: (:) [], ArgumentTransformationMetadataException
    + FullyQualifiedErrorId : RuntimeException

    Property 'DNSName' cannot be found on this object. Make sure that it exists.
    At C:Reboot_TaskXD7_Rolling_Reboot_V1.1.ps1:152 char:93
    + $obj | Add-Member -MemberType NoteProperty -Name DNSName -Value $Server. <<<< DNSName
    + CategoryInfo : InvalidOperation: (.:OperatorToken) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFoundStrict

    Property 'MachineName' cannot be found on this object. Make sure that it exists.
    At C:Reboot_TaskXD7_Rolling_Reboot_V1.1.ps1:153 char:93
    + $obj | Add-Member -MemberType NoteProperty -Name MachineName -Value $Server. <<<< MachineName
    + CategoryInfo : InvalidOperation: (.:OperatorToken) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFoundStrict

    Property 'SessionCount' cannot be found on this object. Make sure that it exists.
    At C:Reboot_TaskXD7_Rolling_Reboot_V1.1.ps1:157 char:93
    + $obj | Add-Member -MemberType NoteProperty -Name SessionCount -Value $Server. <<<< SessionCount
    + CategoryInfo : InvalidOperation: (.:OperatorToken) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFoundStrict

    Property 'SessionCount' cannot be found on this object. Make sure that it exists.
    At C:Reboot_TaskXD7_Rolling_Reboot_V1.1.ps1:224 char:42
    + $active = $RebootList | Where-Object {$_. <<<< SessionCount -gt 0}
    + CategoryInfo : InvalidOperation: (.:OperatorToken) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFoundStrict

    Property 'DNSName' cannot be found on this object. Make sure that it exists.
    At C:Reboot_TaskXD7_Rolling_Reboot_V1.1.ps1:249 char:101
    + $Server.SessionCount = (Get-BrokerMachine -DesktopGroupName $DeliveryGroup -DNSName $Server. <<<< DNSName)

    Any idea? Do i need to include any CMDlet here?

    Thanks,
    Manju

  6. Jacob H

    Hi Manjunath

    I tried running the script on a XA7.5 host but getting the same error:
    Cannot convert the “Citrix.Broker.Admin.SDK.Machine”….

    I tried debugging the script, but I’m not really excelling in Powershell.

    Shaun – can you point us in any direction ?
    Thank you.

    • Can you email me the copy of the script you have. Thanks

  7. […] he has spend a great deal of time developing a so called Rolling reboot script for XenDesktop 7, you’ll find it here, looks awesome! Which automatically brings me to the first method we can use in rebooting our machines, custom made […]

    • Thanks for the pingback Bas

  8. Shaun,

    I tried your scipt but i get the following error when i execute the script. I changed nothing of your script and tried to execute it with the right parameters for delivery group and hold percent. This is the message in Powershell:

    C:ScriptsXD7_Rolling_Reboot_V1.1.ps1 : Cannot process argument transformation on parameter ‘TimeOut’. Cannot convert
    value “Group”” to type “System.Int32”. Error: “Input string was not in a correct format.”
    + CategoryInfo : InvalidData: (:) [XD7_Rolling_Reboot_V1.1.ps1], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,XD7_Rolling_Reboot_V1.1.ps1

    I hope you can help me out what went wrong.

    George

    • Can you email me the exact command you are running.

      Thanks

      • Shaun,

        The command line is
        powershell.exe -noexit -file C:ScriptsXD7_Rolling_Reboot_V1.1.ps1 -DeliveryGroup “Production Delivery Group” -HoldPercent 40

        Configured this in a scheduled task.

        Regards,

        George

        • Can you wait until I release the next version of the script? Probably this week.

          • Hi Shaun,

            Any news on the new script version? Still have the same issue and my command line isn’t that spectacular. 🙂

            Regards,

            George

          • Sorry, I had to work in another project and now away for a few days. I will get it done for Wednesday / Thursday morning.

  9. Kristian

    Shaun, thanks for the script. I have modified it for my own use to set half the servers in maintenance mode, then reboot them later. This should work well in a high usage, high availability place.

    BTW, the error:
    Cannot convert the “Citrix.Broker.Admin.SDK.Machine”….

    comes when there is only one server returned. The line should read:

    [System.Collections.ArrayList]$Servers = @(Get-BrokerMachine -DesktopGroupName $DeliveryGroup | Where-Object {$_.InMaintenanceMode -ne “True”})

    @(…) to force an arraylist.

  10. […] Shaun Ritchie – XenDesktop 7 Rolling Reboot Script […]

  11. Hi Shaun,

    We came across your rolling re-boot script recently and were thinking it might be useful in a Citrix Lifecycle Management blueprint that we are creating to auto scale up/down XenApp running on cloud IaaS. Question, is it copywritten and if not, are there any restrictions on its use or modification?

    Bernie

    • Hi Bernie, I’ve actually been working on an auto scaling script for AWS for about 3 months. It’s about 99% ready. What to do?

  12. Did you get around to create a V2 of the script?

Leave a comment