Tuesday, November 11, 2014

Teaching the XenApp 6.5 Servers to Reboot Themselves

As sleep is a commodity that I have been trying to bank, but all my customers want their servers to reboot at night.  If only there was a way to create an unholy combination of PowerCLI and Citrix Powershell commandlets that could do the work while I sleep.  This needs to be run from a box with both Citrix and PowerCli installed of course and you will need to sub in the IP of your Vcenter server.

asnp Citrix*
Add-PsSnapin VMware.VimAutomation.Core -ea "SilentlyContinue"

$servers=(get-xazone|get-xaserver -onlineonly|where{($_.logonmode -eq "ProhibitNewLogOnsUntilRestart") -and ((get-xaserverload $_.servername).load -eq 0)}).servername
foreach ($server in $servers){restart-vm -vm $server -confirm:$false}
start-sleep -s 600
while ((get-xazone|get-xaserver -onlineonly|where{($_.logonmode -eq "ProhibitNewLogOnsUntilRestart")}) -ne $null)