Powershell Script to correct or restart a XenDesktop 7.x Workstation VM if unregistered or if a launch error is detected.

by Stan Czerno September 1, 2017 16:43 CST

If you are like me and have Static, non-PVS, XenDesktop Workstation VMs that occasionally do not register, for whatever reason, I have a script for you. If you have Static, non-PVS, XenDesktop Workstation VMs that sometimes fail to launch, for whatever reason and your users do not get the "restart" feature or perhaps the restart feature doesn't always work, I have a script for you. If you do not have any Static VMs or any of these issues, I envy you.

I have over 30 static XenDesktop Workstation VMs in my XenDesktop/XenApp deployment, that sometimes, for various reasons, malfunction from time to time. I would go into why I have so many Static VMs, but that would take way too much time to explain. Just take my word for it, it is a necessity, and a pain in the ass. I will probably end up with over 50 when all is said and done.

Anyway, I use this script to assist me with some quick reactionary remediation of the fore mentioned symptoms. I set this script to run every three minutes on one or more of my Delivery Controllers. 

I also modify the /Citrix/<SiteName>Web/custom/strings.en.js file and add the following so the user is aware of the actions the script may take. You can find a link to an example file a the bottom of this post. Be sure to edit your language file if other than english.

CannotStartDesktop: "Cannot start desktop \"{0}\". An automatic remediation attempt will be made in an attempt to correct the issue, please try again in a few minutes. If you still cannot access your VM, please contact the Help Desk.",

CannotStartDesktopSuggestRestart: "Cannot start desktop \"{0}\". Try restarting it. An automatic remediation attempt will be made in an attempt to correct the issue, please try again in a few minutes. If you still cannot access your VM, please contact the Help Desk",

CannotRestartDesktop: "Cannot restart desktop \"{0}\". An automatic remediation attempt will be made in an attempt to correct the issue, please try again in a few minutes. If you still cannot access your VM, please contact the Help Desk",

What the script does is check for any unregistered VMs that are not in Maintenance Mode and has not recently booted up. If a VM meets the criteria the script attempts to restart, or start, the Citrix VDA Services on the VM. If that does not work it can send an email alerting you of the issue, in case you are not looking at Director. 

In addition to checking for unregistered VMs, it also checks to see if any of the VMs has had a launch failure error of either "SessionPreparation" or "RegistrationTimeout". If either of these is encountered the VM is rebooted as long as the LastConnectionError was after the VM booted.

The script is only set to examine VMs that the OSType is like one of the following: $OSTypes = "Windows 7","Windows 8","Windows 8.1","Windows 10". Sorry, no help for Linux Desktops.

CheckDesktopsRegistration.ps1:

Link to file: CheckDesktopsRegistration.ps1

Link to the strings.en.js file: Cstrings.en.js

Tags: , , ,

Catergories: Citrix | Powershell

Add comment