A couple of years ago, I published a post titled XenApp 7.x Reboot Schedules to provide a sample workaround for some of the limitations of the out-of-box reboot mechanism in the 7.x platform at that time. Since then, some improvements have been made; mainly the ability to create multiple reboot schedules for a delivery group, which you can read about in the Citrix documentation.

These enhancements mean that nowadays, many (maybe even most) environments can leverage the built-in reboot mechanism, which is great because that is one less script/customization you need to maintain and worry about. By the way, if you haven’t already, you should also take a moment to read the post Reboot Schedule Internals to get a clearer understanding of how the built-in reboot mechanism works.

However, there are still some gaps around reboot frequency other than daily or weekly and the ability to disable logons on XenApp servers ahead of time in order to minimize disruption to users, which drive the need for some kind of custom, scripted reboot process for some customers.  These requirements seem to be more common in environments with multi-shift 24/7 operations such as call centers, manufacturing, and healthcare.

In addition, since I originally posted about this, I received a few common requests for updates, including:

  1. Can we use a reboot script with Citrix Cloud? – Yes we can!
  2. Could I make it easier for people to modify the script as needed? – I can certainly try 😊
  3. Wouldn’t it be nice if it had some error handling and logging? – Absolutely!

So, between PowerShell cmdlet updates we have added to the product and these requests for functionality enhancements, I decided it was time for an updated script!  I went ahead and added Citrix Cloud integration, broke up the key parts of the script into functions so it is easier to identify what each chunk of code does, and added basic error handling and event logging.

A few things to consider:

  • Instructions on how to run the script can be found in the script’s comments at the top.
  • This solution is OS agnostic.
  • The script assumes all machine names end with a number.
  • The script requires that you provide the name of the Delivery Group the machines belong to and the parity of the machine to be rebooted.
  • The script must be run as an administrator.
  • You need to create Scheduled Tasks to run the script automatically on a schedule. For an on-premises XenApp environment, the tasks need to be scheduled on a Delivery Controller.  For Citrix Cloud, see below for Citrix Cloud considerations.
  • You will need a Scheduled Task for every group of machines to be rebooted (e.g. Delivery Group #1 – Even, Delivery Group #1 – Odd, …, Delivery Group #n – Even, Delivery Group #n – Odd).
  • You can enable/disable the Citrix Cloud portion with a parameter (see instructions for details).

And if you’re thinking of using this with Citrix Cloud:

  • You need the XenApp and XenDesktop Remote PowerShell SDK.
  • As stated in documentation, it is highly recommended that you do not use the SDK on the Cloud Connectors (they are not needed to use the SDK anyway). That means the scheduled tasks will not be scheduled on a Cloud Connector but in whatever machine you chose for this purpose.
  • You will need a Secure Client which you can create within the Citrix Cloud console under Identity and Access Management > API Access.
  • In the Citrix Cloud console under Identity and Access Management > API Access, take note of the customer name provided right above the Create Client button.
    NOTE: As of the time of writing, you will need to enter the customer name in lower case.
  • Update the appropriate fields in the script with your client ID, client key, and [lowercase] customer name.

Lastly, the legalese:

This software / sample code is provided to you “AS IS” with no representations, warranties or conditions of any kind. You may use, modify and distribute it at your own risk. CITRIX DISCLAIMS ALL WARRANTIES WHATSOEVER, EXPRESS, IMPLIED, WRITTEN, ORAL OR STATUTORY, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NONINFRINGEMENT. Without limiting the generality of the foregoing, you acknowledge and agree that (a) the software / sample code may exhibit errors, design flaws or other problems, possibly resulting in loss of data or damage to property; (b) it may not be possible to make the software / sample code fully functional; and (c) Citrix may, without notice or liability to you, cease to make available the current version and/or any future versions of the software / sample code. In no event should the software / sample code be used to support of ultra-hazardous activities, including but not limited to life support or blasting activities. NEITHER CITRIX NOR ITS AFFILIATES OR AGENTS WILL BE LIABLE, UNDER BREACH OF CONTRACT OR ANY OTHER THEORY OF LIABILITY, FOR ANY DAMAGES WHATSOEVER ARISING FROM USE OF THE SOFTWARE / SAMPLE CODE, INCLUDING WITHOUT LIMITATION DIRECT, SPECIAL, INCIDENTAL, PUNITIVE, CONSEQUENTIAL OR OTHER DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Although the copyright in the software / sample code belongs to Citrix, any distribution of the code should include only your own standard copyright attribution, and not that of Citrix. You agree to indemnify and defend Citrix against any and all claims arising from your use, modification or distribution of the code.

The script is available here.  Please note that by clicking on the download link, you are agreeing to the terms of use.

Until next time!
Migs

Enterprise Architect | Citrix Consulting Services