Citrix Chained Reboot Scripts, now supporting Citrix Cloud, Citrix Virtual Apps and Desktops (CVAD), and XenApp/XenDesktop 5, 6, 6.5, and 7.x!
Updated 2018.12.22: Revision 1.9 Now Supports Citrix Cloud!
One script now works with all current and modern versions of XenApp, XenDesktop, Citrix Virtual Apps and Desktops (CVAD), and Citrix Cloud Virtual Apps and Desktops Service from 7.0 and later, through 1811.
In zero-downtime 24/7 environments with shift employees, customers rarely want users to be notified of scheduled or mandatory XenApp server reboots. As a result, most of these environments have reboots disabled or this process is done manually. Unfortunately, this isn’t a good process since the XenApp servers are susceptible to memory leaks which can lead to failure and poor performance. By utilizing the included Chained reboot scripts, environments can take advantage of N+1 overallocation by processing a single server reboot while maintaining the user load on remaining systems. This has been done in such a way that users are not kicked off the system for scheduled reboots. Instead, the server is removed from load balancing until all sessions have been logged off. Once all sessions have been logged off, the server will go down for a reboot.







Looks like the download for XenApp 5 is broken, can you fix it, would like to try it out.
Hi there.
Great script.
Would it be possible to add a feature whereby if the server is set to a defined loadevaluator (i.e. a custom one that we have for test servers) then it is ommited from the process, something like if loadevaluatorname = UATtestingLoadEvaluator skip this server and go to next?
Thanks
Hi there.
Great script.
Would it be possible to add a feature built in whereby if the server is set to a defined loadevaluator (i.e. a custom one that we have for test servers) then it is ommited from the process, something like if loadevaluatorname = UATtestingLoadEvaluator skip this server and go to next?
Thanks
P
Wonderful script Dane. We have XA6.5 environment with both published desktops and apps which are used heavily for customer service. We have a need for disconnected sessions to stay alive for at least 60 minutes before we terminate the sessions. To accomplish this we added the following to the script. I’m sure there is a better way to do it.
[int]$Global:DISCONNECT = “60” # Defines the number of minutes allowed for disconnected sessions
Under the CheckConnections function, just past the if else at the end:
foreach ($d in $sessions){while ($d.State -eq “Disconnected” -and $d.disconnectedtime -gt (get-date).addminutes(-$Global:DISCONNECT)){
Start-Sleep -s 600 } }
Hope someone else can use that.
Correction, moderator please change “disconnectedtime” to “disconnecttime”.
Sorry for the spam. The end result had to be hacked quite a few more times. It wasn’t working properly. I changed the logic to simply remove counters from $i when the disconnected sessions bypass the $Global.DISCONNECT time.
function CheckConnections {
$i=0 # Create a zero valued integer to count number of concurrent sessions
$server = “$args” # Create a variable named server from the first passed variable
$serveronline = @(get-xaserverload | Where {$_.ServerName -eq $server}) # Create a query to validate the server is online before attempting to reboot
foreach ($s in $serveronline) {
$sessions = @(get-xasession | Where {$_.ServerName -eq $server} | Where {$_.State -ne “Listening”} | Where {$_.SessionName -ne “Console”}) # Create a query against server passed through as first variable where protocol is Ica.
foreach ($session in $sessions) {$i+=1} # Count number of sessions, if there are any active sessions, go to sleep for 5 minutes
foreach ($d in $sessions){if ($d.State -eq “Disconnected” -and $d.disconnecttime -lt (get-date).addminutes(-$Global:DISCONNECT)){
$i -= 1 } }
if ($i -eq 0) {
$Global:NoUsers = $True
if ($EnableSMTP -eq $true){$SMTPClient.Send($EmailFrom, $EmailTo, “Server ” + $server + ” has no active sessions.” + $error[0], “”)}
$EventLog.WriteEntry(“Server ” + $server + ” has no active sessions.”,”Information”,”311″)
} else {
Start-Sleep -s 300 }
}
}
It’s a great script. But I was wondering if it’s possible to bypass the Infinite Loop. I just want to run the script once a week to reboot the Citrix servers and then quit the script so it can run the next week on schedule.
I have tried to set $InfiniteLoop = $false, but the started jobs keep on running.