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.
After the reboot has been processed, a procedure will validate that the server has returned from the reboot properly and the load has reevaluated under 5000. This way, if there are any servers that do not return from a reboot, the script will stop processing subsequent server reboots. The script will process through all servers in the farm until all servers have rebooted. Once completed, the script will loop infinitely, repeating this process as frequently the administrator desires (FARMLOOPINTERVAL). For example, if the administrator sets this variable to 72, the farm loop will not occur more than once every three days.
If the environment already has a Citrix Full Access service account, this account can be used to run the scripts as a scheduled task. Otherwise, an administrator will need to create a full access farm administrator account and assign local administrator rights to the XenApp servers. Domain admin privileges are not needed for this account. However, since the script assigns load evaluators to the servers in the farm, XenApp admin rights are needed. The scripts must be configured on a single server for each farm (Preferably the Zone Data Collector). In the case of XenDesktop, this script should be scheduled from a Delivery Controller. This server will manage the reboot processes for all other servers in the farm, excluding the local server from which the script is run.
Feedback welcomed. Enhancements and bug fixes upon request using the comments section below!
Revision History (See Installation and Configuration Guide for Complete Notes)
Date | Description | Revision |
12.22.2018 | – Added support for Citrix Cloud – Validated compatibility with all recent versions of Citrix Virtual Apps and Desktops (CVAD), XenApp, and XenDesktop 7.x through 1811 |
1.9 |
Enter a Valid E-mail Address to Request a Download Link
An e-mail will be automatically sent to you with a link to download. Additionally, you will be notified of any updates to the scripts automatically.
By submitting this form, you are consenting to receive marketing emails from: . You can revoke your consent to receive emails at any time by using the SafeUnsubscribe® link, found at the bottom of every email. Emails are serviced by Constant Contact
I really like the idea of this but we have an Advanced license. Is there any way to do scheduled reboots? I normally don’t have users logged in at night, so I would prefer a script that just checks to see if anyone is logged in and if not, then reboot and if so, then wait.
Can I use any part of your script for XenApp 5 to achieve this? Or do you have other ideas for an Advanced license?
I see now you were talking about the Load Evaluator named Advanced, and not the license type Advanced. I’m now researching Load Evaluators and we will be deploying this script soon.
Great script and process checking!!
Thanks
Hi Many thanks for this script. We have implement the script in our XenApp6 environement. The “Nologon” evaluator get created and also assigned to the first XenApp server. There are no connection on this server, but the server does not reboot. We have installed the SDK on the Datacollector and the srcipts run with the domain Administrator. Could you give me a hint where the problem could be? Does we need to configure something else on the Server or is everything included in the script?
Kind regards
Marcel
Hi The Script works now for the first 2 server. We have 4 servers in the Farm XA01 – XA04.
XA01 & XA02 reboots as expected but then nothing happens again. The last Event Entry is “JW-XA02 rebooted properly, load rebalanced. Proceeding with subsequent servers.” Hopw you can help me to solve this issue.
Kind regards
Marcel
Marcel,
Are you still experiencing this issue with the latest revisions?
Thanks,
–youngtech
I am experincing this same issue with the latest version. It also varries, from cycling through 2-3 servesr, to going through 8-10, the most being about 20 in our farm. However, it has never cycle through the entire 200 servers.
I appreciate your writing this script etc.
What/how does the NoLogon Load Evaluator work??
I’ve been having trouble with getting a working load evaluator for our new XA 6.x farm.
Thank you, Tom
Tom,
If you’re still having issues, please delete the NoLogon Load Evaluator (if it was created) and use Rev 5. I changed the NoLogon logic to use context switching so that the servers being processed will always register a 10000 load.
Thanks,
–youngtech
Never mind, I figured out you used >1% memory usage as the LE. I’ve tested this and it apparently works on our XA servers. Thank you, Tom
Tom,
Thanks for your feedback. In Rev. 5 I changed the LE to use Context Switching with 0/1 as low/high values respectively. This will ensure the servers receive a 10000 load during processing. I too have identified that in certain cases CPU utilization does not register a load properly, even with 0/1 low/high settings.
Thanks,
–youngtech
is it possible to exclude hosts from the script?
Rene,
This functionality has been implemented in Rev. 5.
Thanks,
–youngtech
I have tested your script, and it works for all the servers in the same subnet range… but when I go to subnets in other towns, even though they are connected via fiber, it fails at the err -2147220904 test. Tried googling the err value, and got nothing.
Couple of suggestions, for the filtering, allow wildcards. And conversersly, add the ability to use wildcards to identify what servers should be included (e.g. XA6*)
Rick,
For the time being you will need to use the new exclude logic if you want to process specific servers. I could see incorporating logic for XenApp 6 and 6.5 to populate the server lists based on Worker Groups, but this would require additional dev/testing. Also, if you could send me some more details on your environment, I can attempt to reproduce to see where the script is failing with that error code. Are there firewalls restrictions in place for TCP/UDP ports over the WAN? Does that error code get registered in the Application Event Log? Can you send me as much detail as possible on the error and your environment? As you indicated, the error code alone is not helpful. At this point I would recommend you pick a server to process the script against local servers in each hub/datacenter.
Thanks,
–youngtech
As great as this script is, I am wondering why it sets the LE back to the production LE prior to a reboot? When this is done, it makes the server available to users again who can get sent to the server due to load balancing. and since the server is in mid-reboot, the end user will get an error launching the application. Is there any way to set the LE back AFTER a successful reboot?
Christina,
In order to register the server as operational before moving to the next server in the process list, the script looks at the load value to be less than 5000. The script sets the LE prior to reboot so that when it comes back up it will naturally drop its load reflecting the production LE. Additionally, when you reboot a Citrix server the IMA startup process kicks the server to 20000 load, then 10000 load until all necessary services startup and licenses are checked out. After this has been performed IMA will drop the load to 0. In order to understand why you are getting an error, can you send more details on your environment (i.e. XenApp version, Server OSs w/SPs, HRP levels) as well as the specific error messages that are received.
Thanks,
–youngtech
I have Xen App 4.5 HRP 5 Windows 2003 x64 R2 SP2. What happens when the LE is set back to normal production levels, the server then particiaptes in application delivery..if it is down or unavalible, the end user gets, “The requested applition is not avalible” (not verbaitum but very close) until the server comes back up.
When I try to launch an app that is explicitly published from a server that is in the middle of a reboot I get a dialog box that says: “Citrix Online Plug-in” The remote server failed to execute the application launch request. Please contact your administrator for further deatils.
This is with the normal production LE applied. Which is what would be applied directly before a reboot after the script reports context switches have dropped below the threshold of 1. When I did this process manually, I always waited until after the reboot the apply the production LE so this message would not be an issue. I work for a hospital and people are constantly launching and using the application 24/7 and our user group are they type of people who would call the help desk and the helpdesk would call me in the middle of the night.
Youngtech, I have another suggestion. As users log off and on 24×7, it is a real possibility that the rolling-reboot could be held up by one server, with users who work through the night. Build your array of servers with a T/F switch, then set each server to block logons. test for user sessions, if there are any, move to the next server and repeat the process. Then reboot servers as you come across empty ones. Once the server is rebooted set the switch to .T. so that you don’t process it again. Keep going through the array, until all the servers reboot switches are cleared.
One concern, and the reason why the script was built to pull out only a single server, is that most customers are only built for N+1 availability. Pulling multiple servers out of load balancing can be done with modified logic in this script, but I don’t think it fits most customer environments. If you start going that route you would need to start talking about peak hours and off hours and modifying the max number of servers that can be pulled based on the time of the day. When discussing with other engineers and our customers we decided it’s better to have the script wait for 3 weeks (for example) if there’s a never ending session than to not process reboots at all. Ideally you would have your disconnected, idle, etc. session timeouts set to purge sessions so that this behavior does not hold up a particular server for too long. Hope this helps. Thanks for the feedback!
–youngtech
OK. here is a tricky one..the script is running, the servers rebooting. However, after the POST, the server hangs and IMA services along with all other required citrix services do not start. This only happens when I run the script. It does not happen when I run psshutdown or do a local reboot. I have my citrix service account as a local admin as well as a citrix admin in the AMC. Any ideas?
since out servers are setup to require a reason before shutting down I suspected that the subroutine for reboot was the culprit. We also use psshutdown from sysinternals. So, I changed the reboot sub routine to this and it worked perfectly:
sub StartReboot
AssignLE(strServerLoadEvaluator) ‘Reset the Load Evaluator on this server back to the default
wscript.sleep(5000) ‘Wait for 5 seconds after applying the load evaluator
Log “Initiating reboot process on ” & strServer & “.”, “911” ‘Write a 911 event to the log when rebooting the server
theshell.run(“psshutdown \” & strServer & ” -f -r -t 0 -e p:4:1″) ‘Reboot
end sub
Christina,
That’s excellent to hear! My colleagues and I put a lot of thought into which technologies to use to accomplish this end goal long before I developed and published the script. We came to the conclusion that a combination of VBscript and PowerShell would be the best choice. Our decision criteria was simple, that the output be open source and available for modifications by the Citrix community to fit specific needs!
I’m glad you were able to tailor what I provided to fit your needs. While I am available to make feature enhancements, it always makes me smile when people aren’t afraid to get in and get their hands dirty with a little scripting!
Great work,
–youngtech
Thanks! I did get a little help at narrowing down the issue from my brilliant husband who is well versed in programming! =)
I am running the script in a XenApp 6 environment and the “first pass” works as expected and I receive the event log indicating that, “It has been 0 hours since last loop. Waiting for another 24 hours.”
Then the problem occurs, about 10 minutes after the above event log, the following error is logged, “Unhandled error has occurred in main program: The operation ‘[system.Int32] – [System.TimeSpan]’ is not defined. I have manually entered the portion of the script that calulates the Timespan without issue. Any suggestions are appreciated!
Thanks,
Jason
I believe I found the problem. The error was with line 135 –
$EventLog.WriteEntry(“It has been ” + $intHours + ” hours since last loop. Waiting for another ” + [string]($FARMLOOPINTERVAL-$intHours) + ” hours.”,”Information”,”511″)
After the first pass the variable $intHours is set to TimeSpan. Then after it loops through and attempts to write the log entry it cannot calculate $FARMLOOPINTERVAL – $intHours because of it hold all the TimeSpan values (hours, minutes, seconds, etc).
In order to resolve my issue I changed the logic to $FARMLOOPINTERVAL – $intHours.Hours
Thanks for the feedback Jason. I will take a look and see if I can reproduce this behavior and integrate your changes into the next revision. Hope it works well for your environment.
–youngtech
My concern exactly and the primary reason I’m not replacing our dumb reboot-regardless-of-running-sessions script with this.
I really like the idea that it not only waits for a rebooted server to come online, but also checks that load has normalized to idle level, before proceeding with reboots.
Rasmus,
See my response to Rick above. Using this script shifts the paradigm that reboots only occur during the night. If you have your idle and disconnected session timeouts set properly no server should be hung longer than 24 hours. You just have to weigh all the advantages and disadvantages of using zero interruption logic and processes. Hope this helps,
–youngtech
Hi Dane! I have tried your script in our XA6-environment, but haven’t successfully rebooted any servers yet. The script is set up as a scheduled task from our primary ZDC as described in your documentation. When the task starts, the first server in the farm is assigned the “NoLogon” load evaluator, but then nothing else happens. I have not found any event log entries either, so I don’t know where it stops or what is happening. The scheduled task is run with a domain admin account, which is also a “full admin” in our XA6-farm. Any ideas how to troubleshoot this?
Is it possible that you have sessions hanging out there for an extended period of time that aren’t bleeding off? You may want to check TSAdmin.msc and connect to the server that currently has the NoLogon LE assigned. If you see any sessions or users listed, this could be the reason it never reboots. This is by design.
Let me know your results. Thanks,
–youngtech
There are no sessions on the server with NoLogon LE assigned.
You could be experiencing the same issue that Christina reported above. Do you know if you can use “shutdown.exe -f -r -t 0 -m \servername” in your environment to reboot servers? If not, your servers may require a reason to shutdown. If so, modify the script to use the reason switches Christina mentioned. Please leave feedback with your results. Thanks in advance!
–youngtech
I have verified manually that I can use “shutdown -f -r -t 0 -m \servername” and put that in to the script, but it didn’t make any difference. The server is still not rebooting.
Is the scheduled task set to “Run with highest privileges”?
Otherwise, I suspect it might not have permission to perform shutdowns or reboots.
Thank you Young Tech for the script. Excellent use case if I can get it to work in my Lab (VMware Vsphere5, XA6.5 patched, 2008 R2 SP1, Windows firewall off). I have followed instructions setting up the scheduled job in windows but I get ” the task is current running (0x41301)” message is scheduler. Per my web search, I am using a domain admin account set to Run with highest privileges, with pemission to logon as a service but with the same result. The script does not produce the desired event. I am getting no error messages in eventvwr at all and I am not sure where to look to trouble shoot. Any comments would be useful; I would like very much to get this script working.
Cheers,
Michael,
If the script is truly running you should see several entries in the Application event log with the source of “Citrix Rolling Reboot”. Also, open up Task Manager to see all processes from all users and see if PowerShell.exe is running. You can kill any running PowerShell processes and attempt to restart the scheduled task.
Upon startup the script will immediately log several entries to the Application Event Log. Also, just to rule this out, open a PowerShell window and execute “Set-ExecutionPolicy Bypass -Scope LocalMachine” to change the Execution Policy. If in doubt, refer to my word document (attached above) for instructions on setting up the appropriate Scheduled Task switches to bypass the execution policy.
Thanks,
–youngtech
I finally got the script working, but I’m not 100% sure what made it happen… Thanks for a great script!
Hi –
I’d like to thank for publishing this script. We’re 24×7 shop and this script is a life saver for me. The script is working fine when I first tested it in our environment. It worked fawlessly. However,we’re running into the server hung at shutting down. The server was in shutting down state for a couple of days and won’t reboot until I reset it in VCenter. All our Xenapp are running on VMWare. I was wondering if anyone is having the same issue.
Thanks.
Excellent script, few suggestions:
a) Support to process worker group(s) in XenApp 6.0/6.5
b) Ability to preserve logon prohibited status is enabled after reboot in XenApp 6.0/6.0 (change logon /disable)
c) Ability to allow a given number of servers to fail on the reboot and still continue to run the script (for larger farms)
d) Ability to log to a custom eventview log
Great Script, Works and fixes a big problem I have been having with my PVS cache disk filling up with junk in the pagefile and needing a reboot (also now fixed with a static size).
Are you able to build in the logic to send an email alert with each step that completed along with the event log entry
i.e, the email will have the server name, the time and date the LE was assigned, when the server was reboted, when it refelected as up again etc etc (am sure i missed some logs)
This would be helpfull to send to our service desk so they know which servers reboted etc without having to monitor event logs etc, and could identify any issues that arise after or from the reboots like hung servers etc.
Keep up the good work
p.s have you got a mailing list or just twitter to follow for updates to the scripts
Is there any way to specify a list of servers that will be rebooted, rather than enumerating the farm?
I’d like to use this script on a specific group of servers.
I have tried putting all bar these servers in the exclusion list, but that didn’t seem to work as when I ran a test, it applied the Reboot LE to the server it was running on – Even though it was in the list.
So I’d like to just have an explicit list of servers to reboot.
This would be a great feature. In our farm, we would like to run the script on differnt schedule and cycle for differnt groups of servers. In some cases have sereral groups of serfers rebooting.
First of all, thanks so much for the scripts, they help so much especially with provisioning your xenapp. I have two farms and I will explain my experience so far.
Running xenapp 5 I have seen the following steps which includes a 5 second window when the server LE is set back to default 5 seconds before the reboot command. This introduces a short window when users could login to a server that is going to restart very soon. Wouldn’t it be better to set it to Nologon, check for logons, initiate reboot, and then set LE back to default? I understand that the load is high and then comes down after all the startup work is done, but this 5 second window is a chance for a user to be disconnected from their session defeating the entire reason for a no-impact script. Am I missing something here? I am still using the script because its unlikely a user would connect to that particular server in that 5 second window.
On my XenApp 6.5 farm so far I did have a server reboot but it didn’t return back to allow logons automatically. This may not be the script’s issue, but the server is provisioned like the rest. This caused the whole process to stop and left the server in “no logons until reboot” state. I changed the task to kill the process after running for 3 days to maybe avoid this issue since the script will start again. Would it be possible to retry the restart command if it doesn’t return to “allow logins” within x minutes? I’m still using the script because its nice!
youngtech:
I am very new to powershell Scripting(A week old), This script is rebooting all the servers in the farm, but however, I have a limitation that i can have to finish up rebooting within 3 hours.
3 hours on Sunday: Even numbered servers
3 hours on Monday: Odd numbered servers
Hence I wanted a script which read server list from TEXT file and do the below:
1. Get the LE applied on the servers and export it to TEXT file.
2. Apply the Offline Load Evaluator.
3. See the IDEL session which is more that 1 hour and dissconected session, which should be reset.
4. Send the 3 messages to the users who is active on the server. in 5 min interval.
5. After 10 min, from all 3 messages, reset the sessions and reboot the server.
6. wait for the server to be up, and then re-apply the LE back by checking the text file which we exported in step 1.
I was to achive this partially by
foreach ($server in (Get-Content D:\Server.txt))
{
Get-XALoadEvaluator -ServerName $server | out-file
-Append D:\LEDetails.txt
Select-String D:\LEDetails.txt -pattern
“LoadEvaluatorName” | out-file -Append D:\LE.txt }
Set-XAServerLoadEvaluator -ServerName $server Offline
}
Let me know for any clarification.
Hi,
This is a awsome script and would had helped us a lot.
I am getting an error after my 4 servers are rebooted.
Unhandled error has occurred in main program: The operation ‘[System.Int32] – [System.TimeSpan]’ is not defined.
Running XenApp 6.5, Windows Server 2008 R2 and XenApp6.5_Citrix_Rolling_Reboot_Rev5.ps1
Do you know how I can fix this?
Thank you.
im getting same error – Unhandled error has occurred in main program: The operation ‘[System.Int32] – [System.TimeSpan]‘ is not defined.
first reboot cycle is fine,
first “it has been 0 hours since last loop. waiting 24 hours.” is fine
one hour after crash.
running xenapp 6.0 w2k8r2 – script for xenapp 6 farms build 2011.12.05 revision 5
Peter,
This has definitely been resolved in Rev. 6. Please try the latest code and report back if there are still issues.
Thanks!
–youngtech
[…] http://blog.itvce.com/?p=79 Share this:TwitterFacebookLike this:LikeBe the first to like this. […]
Great, I’m testing the new version now.
I would recommend that you change the script so that it only sends out an e-mail during the restart period. Now it sends out e-mail for every task it performs. Or you could make it as an option, SendEmailEveryTask = True or SendEmailReportAfterCycle…
You deserves credit for the work you have done here, thank you!
-youngtech
I can confirm that the error “Unhandle error has occurred” is solved.
But their is another issue with the script.
When I use default settings, FarmloopInterval=24 and rebootthisserver = $false it’s only rebooting the servers once. In the event Viewer I can find messages like:
08:00 – It has been 22 hours since last loop for ‘AllServers’. Waiting for another 2 hours.
09:00 – It has been 23 hours since last loop for ‘AllServers’. Waiting for another 1 hours.
10:00 – It has been 0 hours since last loop for ‘AllServers’. Waiting for another 24 hours.
11:00 – It has been 1 hours since last loop for ‘AllServers’. Waiting for another 23 hours.
As you can see their is no reboot task executed between 09 and 10.
First time it works but after that it is looks like a never ending loop with no more reboots.
And if you have SMTP to true it spams you a lot with emails. Recommend you to collect this info and send it only once during the farmloopinterval.
Thank you for your support and keep it up! 🙂
Hello,
I received your feedback on my Rolling Reboot blog post. I’m wondering if you have had any further success with the script or to see if it’s still failing? If you are willing, I’d love to take a couple minutes to look over your farm and XenApp environment to see if there’s anything obvious that I may be missing in my approach?
Let me know if you are interested, I’m constantly trying to improve the tool and would love to see why it’s failing.
Thanks,
–youngtech
dane@itvce.com
Hi Dane Young,
Thanks for the wonderfull script.
Could I make one suggestion?
Add a log off force option in the script.If it’s a 24/7 script there needs to be a force logon function in it.
We have a 24/7 company where production users never log off because the monitor system changes in production levels. I already set the log off when idle on 2hours but this doesn’t solve our problem.
We like to see a force log off at a preset time on the “nologon” server.
Saying “server will be shutdown at 2.00 – Please save and log off ….”
Now I need to manually force the remaining users to log off.
Thanks for reading.
Murda,
In this case, why don’t you simply use the built-in Citrix reboot procedures? They do a great job of forcing notifications and reboots, that was not the purpose of the Rolling Reboot scripts. The Rolling Reboot scripts were intended to perform unintrusive reboots on the systems, no user notifications involved.
Thanks
–youngtech
Firstly, thanks for the scripts. I have both a XA 5 and a XA6.5 farm. The trouble I am experiencing is as following:
XA5- The initial running of the script appears to have worked. All servers rebooted, or were in the process of rebooting before I terminated the Script. Afterwards, only two of my 9 servers would reboot and now none of them will. The event logs show the script running and claims that all servers have rebooted, however this is not the case.
XA65 – Similiar story, the script will run, however, it appears to hang and not reboot the server. It looks as if it is putting it into the NoLogon LE but that is where it stops.
Thanks for the help!
Hi John,
I received your feedback on my Rolling Reboot blog post. I’m wondering if you have had any further success with the script or to see if it’s still failing? If you are willing, I’d love to take a couple minutes to look over your farm and XenApp environment to see if there’s anything obvious that I may be missing in my approach?
Let me know if you are interested, I’m constantly trying to improve the tool and would love to see why it’s failing.
Thanks,
–youngtech
dane@itvce.com
Thanks, for your great job.
But I have one question regarding
– The script checks to see if the script is already running (Since Task Scheduler is not smart enough to prevent multiple instances from spawning)
what it exatly will be checked whether powershell is running?, because We have a lot of sheduled tasks that are running at the same time. I got an event script already running ..
Thanks in Advance and a Happy New Year 🙂
Sascha,
This is exactly what it’s checking for. It does a Get-Process to look for PowerShell.exe. If PowerShell.exe is running, the script terminates. If you can think of a better way to accomplish this, I’m all ears. What I don’t want is for several simultaneous threads to be all processing server reboots as that would become a nightmare.
Thanks for your feedback!
–youngtech
This is a very nice script. All of our XenApp 6.5 servers are Virtual servers on XenServer 6.1 and provisioned by PVS 6. What we’re running into is that some of the servers froze and would not take the reboot script. We had to use force reboot via XenCenter or PowerShell for XenCenter. Do you think you can incorporate the XenCenter PowerShell script to force reboot stuck or frozen VMs?
Thanks.
Hang
Hang,
I’m afraid this is out of the scope of what I intended for the script. However, it’s intentionally kept open source, so if you would like to add those modifications to the PowerShell logic, you may be my guest. Ultimately I would want to determine why XenServer is not allowing those VMs to reboot since it’s a very simple Shutdown.exe command for the reboots.
Thanks,
–youngtech
Dane,
First of all thanks a lot for this very useful script and the effort you put into it. It works like a charm!
The one question/problem I have is that the script apparently only looks for active sessions. If users are in a disconnected state, the script will fire up and reboot the server. We have a policy that allows people to be disconnected for 3 hrs. So that they can continue their work from home. I guess the following problem could arise : The last active user on a server disconnects his session so he can continue to work from home 2 hrs later, leaving his word document open. If he/she is on the server next on the list to be rebooted and work was not saved, our help-desk could be confronted with a rather “frustrated” user.
What’s your thought on this?
Thanks!
Dré
Dre,
This is actually very simple to modify if you do not want to bounce disconnected sessions. Simply change the following line to remove the Where statement regarding Disconnected sessions. Change:
$sessions = @(get-xasession | Where {$_.ServerName -eq $server} | Where {$_.State -ne “Listening”} | Where {$_.State -ne “Disconnected”} | Where {$_.SessionName -ne “Console”})
To
$sessions = @(get-xasession | Where {$_.ServerName -eq $server} | Where {$_.State -ne “Listening”} | Where {$_.SessionName -ne “Console”})
I decided it was best to ignore disconnected sessions as I can’t assume that every environment has disconnect session timeouts configured. Let me know if this helps.
Thanks,
–youngtech
dane@itvce.com
Great Script! I am still working with a XenApp5 farm, and can’t bounce servers that have “disconnected sessions”, unfortunately not a vbs scripter….could you tell me what I need to edit to exclude servers if they have disconnected sessions???? Thanks in advance!
Hi Sonia,
Find the following lines:
if SessionState(aSession.SessionState)<>“Disconnected” then ‘Don’t count disconnected sessions
sess=sess+1
end if
and simply change them to:
sess=sess+1
This should ensure Disconnected sessions aren’t flushed automatically. Please be sure to set proper disconnected session timeout values, otherwise the servers will never reboot.
Thanks!
-youngtech
Could you explain the puirpose of adding copyright nomenclature to the script:
“Added Copyright tag lines to top and bottom of the scripts.”
Is this reboot script not a free tool? Are there restrictions to using this script and if so, what are they?
Hi Cliff,
Thanks for your feedback. I have sent you a response on Twitter, but I wanted to make sure others knew there were no restrictions with the script for personal or professional use. Simply leave my name and credit in the header and footer of the script.
Thanks,
–youngtech
‘Created by Dane Young, Entisys Solutions Copyright 2010, 2011
‘Build 2011.12.05 Revision 5
In order to be used in a production environment, do we need to paid to use this script? License?
What’s the license agreement?
Maria,
No license agreement required. Simply leave my name and credit in the header and footer of the script. Free for personal or professional use.
Thanks
–youngtech
Hi,
I am experiencing the following issue using the reboot script (build 2012.11.26 rev 6) in a xenapp 6.5 farm :
One we start running the script it reboots all the servers once as planned (24hrs cycle). But after the first cycle of 24 hrs we get the following msgs :
It has been 23 hours since last loop for ‘SessionHosts’. Waiting for another 1 hours.
It has been 0 hours since last loop for ‘SessionHosts’. Waiting for another 24 hours.
It has been 1 hours since last loop for ‘SessionHosts’. Waiting for another 23 hours.
And no more reboots occur. If I stop and start the script the reboot cycle works as planned, but only once and then we get the above msgs without any more reboots.
Hi Andre,
I received your feedback on my Rolling Reboot blog post. I’m wondering if you have had any further success with the script or to see if it’s still failing? If you are willing, I’d love to take a couple minutes to look over your farm and XenApp environment to see if there’s anything obvious that I may be missing in my approach?
Let me know if you are interested, I’m constantly trying to improve the tool and would love to see why it’s failing.
Thanks,
–youngtech
dane@itvce.com
Hi Dane,
Since the “Nologon” policy is enabled on the server and users are working on the “nologon” server.
New applications which are launched are opening on a new citrix server meaning the users needs to wait the login of every newly opened application.
Is there a way that users who’re currently working on the “nologon” server can still launch application on that server?
regards,
murda
Murda,
Unfortunately I am not aware of an easy way to accomplish what you’re looking for. I will let you know if I find a solution for this, but generally new application launches will be shifted in order to bleed off the server of active sessions.
Thanks,
–youngtech
Great script YoungTech. Hoping you can help me figure out why the script does not restart the loop after the FarmLoopInterval timeout has expired (24 hours). I see in the log that it counts down to zero, “It has been 0 hours since last loop for ‘AllServers’. Waiting for another 24 hours.” But nothing happens. Shouldn’t the script start the reboot cycle again?
What am I missing?
Hi Stephen,
This should be resolved.
Thanks!
-youngtech
Great script youngtech but I stuck on something I hope you can help with. The script runs correctly the 1st time but when it is time to repeat after 24 hours, all the log file shows is “It has been 0 hours since last loop for ‘AllServers’. Waiting for another 24 hours.”. But the script never runs through the process again unless I kill the powershell process. I am on Win2008 R2 and XenApp 6.5.
What am I missing?
Hi Stephen,
I received your feedback on my Rolling Reboot blog post. I’m wondering if you have had any further success with the script or to see if it’s still failing? If you are willing, I’d love to take a couple minutes to look over your farm and XenApp environment to see if there’s anything obvious that I may be missing in my approach?
Let me know if you are interested, I’m constantly trying to improve the tool and would love to see why it’s failing.
Thanks,
–youngtech
dane@itvce.com
Hi Dane,
I’m loving your script and it is definitely the right tool for the right job. Thanks for putting it together. I am, however, having the same issue that has been mentioned a couple of times in this thread. The first time the script is run, it cycles through and reboots the servers, however, upon successive countdowns once it reaches the time that the scheduled task is set to kick in, the countdown starts all over again, instead of continuing with the countdown. I have my FarmLoopInterval set to 72 hours instead of 24 hours, but it appears that even though the task scheduler recognizes an instance is already running and does not execute the task again, the countdown timer is reset for some reason.
[…] rolling server reboots to enable this. There are some nice Powershell scripts to do this at http://blog.itvce.com/?p=79. I’m using a Reboot Manager Tool I’ve developed myself for the job. I’m planning […]
Hi Dane
I’m getting the same issues as some of the above responders. I have it set to 150 hour reboot cycle.
In the event log I get all of the 511 events counting down, however when it gets to 23 hours the event says waiting for another 127 hours. The next event says 0 hours since the last loop, waiting for another 150 hours.
It is never doing another reboot after the first one
Any ideas?
Thanks
Jon
(great script BTW)
Still working on tracking this down. Thanks for your patience Jon.
–youngtech
Hi Jon,
This issue has been resolved, please test out the latest Rev8.
Thanks,
Dane
Getting the same problem as Andre
(One we start running the script it reboots all the servers once as planned (24hrs cycle). But after the first cycle of 24 hrs we get the following msgs )
Quick fix is RebootThisServer variable set to true.
And one more thing could you give the option to have the nologon variable with 6.5 farms. When you run published applications. You do not want a new session/logon on a diffrent server for new application the users starts. You only want to avoid new logins of new users.
– Released XenApp 6.5 compatible version utilizing the ProhibitNewLogOnsUntilRestart and removing syntax for the NoLogon load evaluator.
This is good if you do published desktops you do not want this behavior on published apps. You want them to stay on the same server in the same session. So the nologon variable would be better since published apps keep starting on the same server for the already loged on users.
Thanks for a excellent script.
Regards
/Ossian Ericson
Awesome feedback Ossian! I’m still working on tracking down the root cause for the loop failure. I will release a new version once I’ve determined the root cause and fix. Thanks!
–youngtech
[…] http://blog.itvce.com/?p=79 […]
Hi,
How can i exclude some servers from rebooting policy?
Hello Dane
I have used a modification of this script for quite a while now in a XenApp 5 Environment, great work. I anted to have a look on the latest revision (XenApp5_Citrix_Rolling_Reboot_Rev5) unfortunately I’m not able to download it.
The farm consists of 120 Servers separated into 2 zones splitted by firewall. During the night I have only little load compared to what I have during the day. I have to reboot all servers every 2 days. Therefore I have modified the script to run just on a single server and I trigger it from an additional Script which takes the servernames from an input file. This way I can disable half of the farm at 5pm and all servers will reboot during the night as soon as the users are logged off. Since we use published desktops, the way your script works does not fit for me, because it would take too long to cycle through the whole farm. The problem now is, that after about 30 scheduled tasks no more tasks will be scheduled.
Therefore I’m looking for a new method. to disable a group of servers (seperate inputfile, group in console, etc) and then let the script cycle until all users are logged off and then boot the server.
in cas you have any ideas I would appreciate to hear.
best regards
Hanspeter
Great script working really well, I do have a suggestion.
It would be good if there was an option to use the server’s uptime to select the next server to reboot rather than alphabetical order.
For example I am rebooting 20 server with your script the other day the script has got to server 18 I am had to reboot the server hosting the script, so when the script started up again it started back at number 1 whereas if was using the uptime it would have carried off where it left off rebooting server 19 next.
Also there are times when I need to manually reboot a server say server 2 has been rebooted by the script so 3 is next but I have manually rebooted 3, the script may as well skip 3 and it would if it used the uptime.
Thanks
Phil
[…] http://blog.itvce.com/?p=79 […]
Hi Dane,
I have found the error not booting after FARMLOOPINTERVAL has elapsed. On Line 204 (while ($intHours.Hours -lt $FARMLOOPINTERVAL) # Compare to see if the time elapsed is less than the farm loop interval)
instead of using $intHours.Hours which will never be greater than 23, $intHours.TotalHours should be used.
best regards
Hanspeter
great stuff dane. I am trying to get a copy of the XA5 VBScript but there seems to be a problem with the download link. Not sure if this is the correct place to mention. I appreciate the work. Thanks.
-Aaron
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.
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 }
}
}
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
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
Looks like the download for XenApp 5 is broken, can you fix it, would like to try it out.
The XenApp 5 link is broken, were these files removed?
Build 2012.11.26 Revision 6: There is an error in the following comparison:
} while ($intHours.Hours -lt $FARMLOOPINTERVAL) # Compare to see if the time elapsed is less than the farm loop interval
It should be:
} while ($intHours.TotalHours -lt $FARMLOOPINTERVAL)
$intHours is a timespan object. The .hours-method will for instance return 3 hours if the timespan object is 1 day and 3 hours – alas if $FARMLOOPINTERVAL is 24 or greater, then the while loop continues for ever.
Thanks Bjorn. This has been fixed, try downloading again.
–youngtech
Thanks for the perfect script!
I did not use a service account that was local admin on all XA servers, so the reboot command (shutdown.exe) returned an Access Denied. The script does not check if the server has really been rebooted. It continues after 60 seconds and reports the load is under 5000 and continues. But the server still has the status “Prohibit Logons”. After a few hours all XA server were “handled” and they did not accept any sessions accept for one XA server ;).
Maybe it is possible to add a check before the serverload check to see if the server is still not accepting sessions. Or even better: check the errorlevel of the shutdown (reboot) command.
I now use an account that has local admin permissions on all servers, so it is working!! This is just for people like me not using an domain admin user..
I really like what you have done with this script. I have had this sitting on the shelf since Rev5 waiting for some time to see how it would work in our environments. I have loaded the two versions (6.0 and 6.5) on some test farms, and i am noticing something consistent between the two scripts (present with Rev6 and 7). what we are seeing is the script will set a server to prohibit logons (or nologon LE) like it should and wait for the reboot until all users have logged off. but if at least 1 user is logged on it will continue after the 30 min window and attempt to process the next server and start over again once the FarmLoop interval has passed. While i understand the logic of this, what can occur (and has in testing) is if multiple servers have 1 user logged in, it can create a scenario where more servers than the ‘MAXSERVERS’ variable are set to prohibit logons. As in the case of our small test farms (consisting of two servers in each farm)
First scenario: server 1 launches script via scheduled task, but has a user logged in. script correctly processes server 2 and it successfully reboots. After 30 min, server 1 is tagged for reboot and set to prohibit logons, FARMLOOPINTERVAL passes, server 1 has not rebooted but is still prohibiting logons and reboots start again on server 2. (i suspect it would start again on the entire farm if it was larger)
second scenario: server 1 launches script via scheduled task, has users logged in. script starts to process on server 2 but server 2 has users logged in, so it only set to prohibit logons. After 30 min, server 1 starts to get processed but because a user is logged in, it too is only set to prohibit logins. after FARMLOOPINTERVAL passes, process starts over again. no server reboots, all are set to prohibit logons.
the only modifications made for testing was to set the SMTP/Email so it would work and Set the REBOOTTHIS SERVER to true and FARMLOOPINTERVAL to 1 hour. Granted this is a short window but it is a test lab and.so i could see it work within a reasonable time frame
Do you have any suggestions for the following:
– modification of the script (or variable) so it will sit on one server till the reboot is complete; once done then it could move on to the next server.
I am ok with controlling the looping by setting it as a scheduled task. With no one logged into the servers the script works as expected since it handles hosting server last, the reboot of the hosting server prevents any loops.
Dane,
Great script. Just have a couple of issues. We have many, many farms. From 4.5 to 6.5. ON the 6.5 farm we have several farms that we need to set with different configurations. I have configured a script to run against a couple of worker groups for one app. But if i try to run another script with different configurations on the same ZDC, it won’t run because the powershell.exe is running. Any ideas on how to get around that?
I also have a problem with the script that is running. Some of the notifications work fine, up to the point where it says that there are no users on the server. From that point on the email notifications, such as the server is rebooting and the server is back up and running, will not go out. The Event log entry will work, but the email for that same event doesn’t work. I can’t find any difference in the commands in the script that do work vs. the ones that don’t work. Any suggestions on what to look for there?
Thanks,
Michael Boggan
If the FarmLoopInterval has passed and not all the servers in the farm have been processed (Session remain on the servers beyond the interval), does the script bypass the remaining unprocessed servers and start again with the first server?
Hi,
great script, thank you!
Some of our XenApp 6.5 farms have got problems with ghost sessions. Same issue as described here: http://discussions.citrix.com/topic/269840-sessions-remain-in-console-window-after-log-off/
Only workaround is to restart IMA service.
Your script treats these ghost sessions as active sessions and so servers won’t reboot:
$sessions = @(get-xasession | Where {$_.ServerName -eq $server} | Where {$_.State -ne “Listening”} | Where {$_.State -ne “Disconnected”} | Where {$_.SessionName -ne “Console”})
It would be nice if there was a possibility to restart IMA service within your script.
What do you think about that? Is this possible or should we restart IMA service with a separate scheduled task?
Regards
The sharefile link to the script is not working for me.
please let me download script
Hi Dane,
First off, thanks for the continued work on this tool! I have a small XenApp 6.5 farm with three servers (two production and one test box). The script (rev7) is setup to run from the zone data collector. In the event log I see it starting and beginning to process the other two servers in worker group “AllServers”. Logons end up disabled on all three servers but no reboots happen.
I checked for sessions and all I saw was a disconnected Services session ID and the listener.
The script is set to run with a service ID set as local admin on each of the servers.
Here are the variables as I have them defined:
[int]$Global:REBOOTINTERVAL = “15”
[int]$Global:FARMLOOPINTERVAL = “2”
$Global:REBOOTTHISSERVER = $true
$Global:EXCLUDESERVERS = “”
$Global:WORKERGROUPS = “”
[int]$Global:MAXSERVERS = “1”
$Global:ENABLESMTP = $true
I’d love to get this working reliably so let me know if you need any more details.
-Cameron
Thanks for the great script,
i have only one general question: If you are using PVS with XenApp6.5 or Xendesktop 7.5, what are you doing with a vDisk Update for a Client Application, with the first launch of the client application, the server component is upgraded. In this case all users on terminalservers with the old client application version can no longer work with the server component. Have you got any ideas other than rebooting all terminalservers manually.
Regards
Dennis
Nice script!
I changed line 192:
“‘ from delivery group ‘” + $deliverygroupname
into
“‘ from worker group ‘” + $workergroupname
Regards!
Great script.
I have a problem with the farm loop, after reboot of all servers it starts counting towards next reboot loop. When it gets to 24 hours it just starts counting from 0 with no reboot loop executet. Please advice on how to sort this out. The farm is 6.2, so we are using the XenApp6_Citrix_Chained_Reboot.ps1
Hi Kim,
Did you mange to sort out the loop issue, I am also having the same issue, it does not loop
Hi Dane,
First of all thank you for this awesome script.
I also have the same problem as above people that the script reboots the servers once, after that it stays in a waiting loop. I was wondering if you have some more idea’s about this. I thought maybe a quick and dirty trick was to close the script after the last reboot since task schedular restarts it anyway when the next reboot cycle needs to be started. Just a idea.
-Mark
Dane, wanted to send you a note and say thanks for your work on this. I maintain about 12 farms across 8 domains (XenApp 5, 6.0, 6.5 and soon 7.6) While your scripts didn’t fit our exact needs. I was able to make some significant modifications and combine all into one script that i can pretty much pickup just drop on a server in one of our farms and then set it up a scheduled task and walk away. Your work has made managing our complex environment a lot easier. Keep up the good work!
I implemented the script in our lab environment. I set FARMLOOPINTERVAL to 24h. After starting of the scheduled task all server have restarted once as expected. But after then looping counts down from 24 to 0 and starts over again and again. Did I something wrong?
@Cumhur Uerel,
There is a bug in the script (at least in XD7) – search for $intHours.Hours and replace it by $intHours.TotalHours and the script will work as supposed.
I am getting the following error in the event logs when I run the script. Not sure what is causing it.
Unhandled error has occurred in main program: Cannot validate argument on parameter ‘Job’. The argument is null, empty, or an element of the argument collection contains a null value. Supply a collection that does not contain any null values and then try the command again.
Thanks again
Dane, thanx for the work on this. We just started using this because we felt our profiles were being corrupt when our servers rebooted nightly at 3AM and users didn’t log off.
We do have a couple of questions. We have tried this using scheduled task in couple different ways, starting at 8PM and upon restart of the Zone Controller server. it seems to run initially, but after the second loop it doesn’t. it disables logons but then doesn’t reboot the server and starts the timer over.
also, how many powershell processes should we see if we have two WORKERGROUPS defined? we currently have 4 powershell processes running.
thanx again for your work on this script for others!
[…] looking for some scripts I ended up finding the one fellow CTP Dane Young wrote and posted on his site. The problem IMHO it is overkill for many customers (what ends up making it complex, especially for […]
Hi,
Great script! Unfortunately I cannot get it to work properly. The script seem to run fine and i get this in the event log: “server rebooted properly, load rebalanced. Proceeding with subsequent servers.” but in reality the only thing happening is that logons are disabled on that server, no reboot occur. It’s a XA6.5 farm with HFRP4.
Regards,
Robert
Hi, I want to use this script in my Xenapp 7.5 environment. On which server do I need to create the Scheduled task? On my provisioning servers (I have 2 of those) on my storefront servers (also 2) or on one of my xenapp workers (I have 20 of those).
Hello Ruben,
You would create the script on your delivery controllers. I would presume those are the same as your StoreFront servers as you didn’t specifically mention any additional servers.
Thanks,
@youngtech
This looks like something i would like to try, but the sharefile link used for download seems to be down or doesnt exist anymore. is it still available to download and try? Thank you.
Just tried the link and it seems to be working.
@youngtech
Hello Dane,
Great script, but i have one question. I’ve tested it with one delivery group and that is working fine. But after the last server rebooted, the script doesn’t stop. In the script i set the Farmloopinterval to 8 hours but it constantly starts over again. Do i have to manage this in the schedule? Or do i have to set other variables? I use XenDesktop 7.6 and only use applications and no desktops
Dane,
i am testing with your script and i have another question. When a server has one or more sessions, the machine is put into maintenance mode and the script goes to sleep for 5 minutes and then again checks if the server is free of sessions. But the script is waiting until the sessions are gone and the remaining servers are not rebooted. Is there a way to skip the server with sessions and tries it at the end? In that way all other, not rebooted servers, are being rebooted and do not have to wait.
Hi Dane,
i have implemented a GPO with a idle and disconnect timer and also session lingering. With that implemented i am able to be 99% sure that in our environment at max unuses sessions are removed and the script goes further. I am now testing the script and hope the script will exit when it finished rebooting the servers.
Hi Dane,
the script has rebooted the servers, one server was offline (was skipped) and one server we received an email that is was rebooted, but it was not. After the last server was rebooted, the script remained active. The farmloopinterval was set to 8 hours. Now i am doing a test with one server and the scheduled task will be terminated after an hour, which i configured in the scheduled task. Is this the way to avoid a constantly running script?
[…] Dane Young – Citrix Chained Reboot Scripts, now supporting XenApp 5, 6, 6.5 and XenDesktop 7.0, 7.1, 7.5, and 7.6… […]
I have implemented this as a scheduled task that starts at 10 PM, using your guidance on creating a scheduled task. It seems as if the reboots keep getting later and later in the morning. It is only rebooting four servers. I would like those servers to reboot between 10 PM and 2 AM, so that they reboot during a monitoring blackout period. How can I do this?
One nice thing to have would be to have a way to have the script (in XenApp 5) skip a server if its Load Evaluator is the same as the Maintenance LE (or possibly also look for a load of 10000). This would help prevent servers that have been flagged as offline to stay offline if it is required for any particular reason.
Does anyone have any issues where the FARMLOOPINTERVAL is not working right ? I set the interval time to 170 hours, but it seems that it goes straight back into the loop to disable the first server instead of waiting. the numbers I see in the email I get (of how many hours are left) are also completely wrong. I’ve got about 30 servers, so it takes a while before all of them are done, but I would prefer the script to wait a week after the last server is done…
Any help would be muchly appreciated 🙂
Dan.
Can’t download the file. By clicking onto ‘Click to Download from ShareFile.com’, the following message appears: ‘The link you are trying to access does not exist.’
Is the link broken?
“The link you are trying to access does not exist.”
Does the download link work for anyone?
I was trying to download the rolling script, but the links says it’s unavailable. Any assistance would be appreciated. Thank you
i had a similar problem before, it turned out my company was blocking sharefile based sites as personal storage solutions. once i got home on a personal device i was able to download it fine. I am not sure if this is the same scenario, but if it is, try accessing from a personal device on a personal or public network.
Trying this on XenApp 7.6. Something is wrong. I set it to process max 2 servers at the time with 30 minute intervals and it should process the entire farm in one week (so 168 hours).
However, now every 30 minutes it puts a server on maintenance mode, it doesn’t stop at the 2 max servers I specified. This goes on until all servers are on maintenance mode and nobody can login any longer.
Any idea?
Download is working now. Thanks!
hello Dane,
i have placed this script on our XenApp 7.6 Farm. in Task scheduler script showing as running however servers are not getting rebooted. could you please let me know is there any permissions required to get the server rebooted or something i need to check
Regards
SK
For some reason I can not get this to run properly on one of my Xenapp 6.5 farms. I have a second farm that it works as intended. Both scripts are configured identical. I have it running off of the ZDC. I see powershell.exe running but the servers just never reboot. Nothing in the event logs that I have found. Any help is much appreciated!
Hey
Everything appears to be working except for the reboot part
My troubleshooting appears that it’s kicking off the
New-BrokerHostingPowerAction -Action ‘Restart’ -MachineName $server
which the server sits as ‘proccessing’
Is there a way to bypass that method so it will be forced to use the
Invoke-Expression “Shutdown.exe /m $dnsname /r /t 0 /c “”Shutdown scheduled by Citrix farm chained reboot.”””
instead?
Hi SK,
I removed ‘@’ in line 125:
$sessions = (get-brokermachine $server).SessionsEstablished
and also changed line 147 to:
Invoke-Expression “Shutdown.exe /m $dnsname /r /t 0 /c ‘Shutdown scheduled by Citrix farm chained reboot.'”
Afterwards the script functioned as expected.
Great work!!!! Thanke you Dane.
Hi Robert,
i have made as suggested by you, but still its not working. FYI: I am using this script on XenApp 7.6 Farm but no luck
Regards,
Shekhar Reddy.
How do you handle prelaunch sessions? I would like to make a distinction between ACTIVE sessions and prelaunch sessions.
Great question! Not sure how these sessions would be registered, but I’m sure we can figure out a way to adjust the script to handle these types of sessions. Let me know if you need more help researching adjustments to the script.
Thanks!
–youngtech
Rather than check for the active sessions, check for active applications. If you replace $session value with the return of “(Get-BrokerSession | ? { $_.AppState -eq “Active” }).count” then a value of 0 indicates that no active applications are running and the server can be rebooted.
[…] Download Now […]
[…] young has done a advanced script for this :http://blog.itvce.com/2013/12/09/citrix-xenapp-rolling-reboot-scripts/ I haven´t tested it but it sounds […]
Hi Dane, Great script and works 99.999%
The problem I am having is that I cannot only get it to reboot a single server per delivery group at a time, How can i get it to reboot more servers?
I have 220 (110 per site) servers that I need to run this against and so far has taken 4 hours and only done and reboot 87 per site.
I have the the reboot interval set to 5 and the maxservers set to 10 but it only seems to do one at a time and does not move on until it is finsihed
Thanks
I am having the same issue, XenApp 7.6 LTSR CU1. It will only reboot one server at a time, even though I have it set to 5 for max servers. I tested it in my lab which is on the same version and its doing the same thing. This worked previously with the original 7.6 release. Is there anyway we can get an updated script that fixes this functionality? It would be greatly appreciated!
Thanks!
Trying to implement this into our XenApp 6.5 farm, the script will go through and process servers in the farm disabling logons but never actually reboots the servers.
Hello Dane,
Thank you for this amazing script!
If possible, I would like to suggest the change below. With this code, you will check if the same script was called (not only check for any Powershell). That way, if some other admin logs into the server and forgets the Powershell console open, it won’t impact the execution of the scheduled task.
Remove this:
$processes=0
$powershells = @(get-process | Where {$_.ProcessName -eq “powershell”}) # Query all running processes to see if Powershell is running
foreach ($p in $powershells) {$processes+=1} # Validate that there is already a powershell instance running
Add this:
$processes=((Get-CimInstance Win32_process -Filter “name = ‘powershell.exe'” | where {$_.CommandLine -match $MyInvocation.MyCommand.Name} | measure).count)
Hello, is there any support for 7.9?
I’m currently using it on a 7.9 farm. I’m still looking into an issue with it not working with my Windows 7/XenDesktop delivery groups.
Has anyone tried this script in a XenApp 7.9 farm?
Hello Dane,
On line 197 of the 6.5 script I had to replace the $Deliverygroupname with $Workergroupname. This was from a download I did last week.
Thanks,
Alain
Is the Reboot Interval the amount of time between when the last server was rebooted and when the next server will be rebooted?
Could I get a more detailed explanation of the Farm Loop Interval?
Hello, We are running Build 2014.12.03 Revision 8 of this script in our Xenapp 6.5 farm and have noticed we’re only getting 43 of the 130 servers rebooted. We have them split in to 2 different Workergroups and do see them from each rebooted however just not all in each. Is it time upgrade the script or do we not have something set correctly to cover them all? Thanks!
I’ve started testing the script in my 7.9 environment. So far so good. I’ll know better in a couple of days.
Hello,
thanks for the amazon script, we are using it since years in our XenApp 6.5 environment.
I tested it with XenDesktop 7.9. Unfortunately the script is not working. In the eventlog you can see “Initiating reboot process on XXX\XXX”. But the server ist not rebooting. Also “XXX\XXX rebooted properly, load rebalanced. Proceeding with subsequent servers.” is logged, but the server has not booted.
Any ideas?
Thanks!
Tobias
Were are using 7.13, sorry.
Works great, Thank you.
For lines Tyron mentioned, I modified mine as
$processes=((Get-CimInstance Win32_process -Filter “name = ‘powershell.exe'” | where {$_.commandline -like “*XenApp_XenDesktop7_Citrix_Chained_Reboot.ps1”} | measure).count)
In line 277 of the Xenapp 7.x script this line “$checkdeliverygroup = @(Get-BrokerDesktopGroup | where-object {$_.Name -eq $deliverygroup -and $_.SessionSupport -eq “MultiSession”})” precludes XenDesktop Delivery Groups. Is this by design? I thought this script to also reboot XenDesktop systems?
I am looking for a script for weekly rebooting of our PVS servers. I only want the particular worker groups to be rebooted utilizing the script. I want to start the process on Friday evening and have all of the servers rebooted before Monday morning. The servers would remain online throughout the week, and the process would begin again the following Friday. I believe this script would be compatible for these requirements, correct?
Please send me the update.
Download dont seem to work ..atleast fo rme… .. Sharefile keeps askin username and password…. after entering i land on my sharefile page..
We have an existing environment that works great with an earlier version of the script (Build 2014.12.03 Revision 8).
We have a new CVAD v1912 based on W2K19. The script puts machines in maintenance mode but the machines don’t appear to reboot and come back out of maintenance mode.
With the same settings as the old script in the new environment, the old script works as expected.
Any help will be appreciated.
We’ve been running this script on both our 6.5 Farm and our 7.15 Farm (in the process of getting off the 6.5 farm). Recently on our 6.5 Farm the events for the script are reporting that a server has rebooted, however, checking the server it hasn’t actually rebooted and the machine stays in “prevent logins until restart”. Furthermore, the events will occasionally report an error, and instead of only processing the max allowed servers, it sometimes goes rogue and will mark additional servers for maintenance. Any thoughts on why the server isn’t actually getting restarted anymore?
Love this script, however, in the environment that it is being used, the company only wants servers rebooted over the weekend. This is also helpful for monitoring proper maintenance mode during the week. Any suggestions for how to have the script end after all delivery groups have been successfully rebooted. Currently we have the interval set to 180 hours and the scheduled tasks is set to end script after 4 days. With this running in 7 different firewalled domains each weekend, it is generating an excess amount of emails. Thanks in advace.
I know it’s 2022, but this script is still useful and awesome!