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"
connect-viserver 127.0.0.1

do{
$servers=@()
$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}
$servers=""
get-date
start-sleep -s 600
}
while ((get-xazone|get-xaserver -onlineonly|where{($_.logonmode -eq "ProhibitNewLogOnsUntilRestart")}) -ne $null)


Enjoy.

No comments:

Post a Comment