|
Recently, Andy Zhu published a PowerShell script that utilizes the undocumented CPSCOM to take a server “offline”. I took a look at it and thought, “Wow, this is great. I can use something like this for my maintenance scripts.” So, I took Andy’s idea and created a vbscript version of the script. Having this as a vbscript reduces the complexity and overhead of automating a PowerShell script.
So why not use the standard CHANGE LOGON /DISABLE command? Well, in the old days, this is what we used. That was until Presentation Server 3.0. Citrix tried to enhance the functionality of the CHANGE LOGON command but broke it instead. Well, technically it works as designed but it was (and still is) poorly designed. If the IMA Service did not start properly after a restart, it was time to take the “walk of shame” to the Data Center as RDP connections would also be disabled. Second, there are several cases in which you would want the servers come back online after a restart. Using a startup script to force the IMA Service to start and change the logon status works intermittently at best. What about the Customer Load Evaluator Method? Using a Custom Load Evaluator to take a server offline solves the problem with RDP Console from being locked out but suffers the same problems with trying to automatically bring a server online after a reboot. Tell me about the Andy Zhu method and why is it better. Andy’s method uses the Health Monitoring and Recovery feature of PS 4.5 (Sorry PS 4.0 users) to take a server off of the Load Balancing table. By just taking the server off the table we gain the following benefits: - New connections are no longer routed to the server
- RDC Connections are still available
- A reboot will place the server back on to the LB table
- Use HMR. Automatically have a server skip its scheduled reboot if too many servers are offline.
*Note the HMR node under the Farm Properties HMR node under the Farm Properties of how many servers can be taken off the LB table. Using this script (and Andy Zhu’s PowerShell script) to take a server offline will count against this number. If you try to run the following script and the farm has reached it’s limit (number of servers that can be off the LB table) then the script will report an error. You can increase this number accordingly but be sure to leave a buffer for the HMR to do its job too. The advantage of this vbscript over PowerShell is you don't have to worry about the security complexities of running PowerShell scripts automatically and you don't need the overhead of the .NET framework. Usage: cscript.exe disablelb.vbs [ComputerName]
Other Notes: - If the [ComputerName] is not specified then the Computer Name of the machine that is executing the script will be used
- Does not have to be run on the server that you wish to remove from the load table
- Can use enablelb.exe [ComputerName] to place the server back on to the LB table
- A reboot or restart of the IMA Service will also place the server back on to the LB table
- Use the QUERY FARM /LOAD will display current servers in the lb table as well as their respective load. Servers that have been removed from the lb table will not show up in the list.
- The IMA Service needs to be running. If it is not, the script will report an error (Error #2).
EnableLB.vbs: '*************************************************************************** '* '* disablelb.vbs script written by Joe Shonk (
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
) '* Version 1.0 '* '* Based off of Andy Zhu's PowerShell Script '* http://community.citrix.com/pages/viewpage.action?pageId=37388904 '* '* Syntax: cscript.exe disablelb.vbs [Computer Name] '* '* This script is provided as-is, no warrenty is provided or implied. '* The author is NOT responsible for any damages or data loss that may occur '* through the use of this script. Always test, test, test before '* rolling anything into a production environment. '* '* This script is free to use for both personal and business use, however, '* it may not be sold or included as part of a package that is for sale. '* '* A Service Provider may include this script as part of their service '* offering/best practices provided they only charge for their time '* to implement and support. '* '* For distribution and updates go to: http://www.theshonkproject.com '* '***************************************************************************
On error resume next
Const DISABLELB = 0 Const ENABLELB = 1
Set objArgs = WScript.Arguments
If objArgs.Count > 0 then strComputer = objArgs(0) Else Set objShell = CreateObject("WScript.Shell") strComputer = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") End If
Set objSWbemServices = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
If Err.Number then wscript.echo "Error: " & Err.Number wscript.quit (Err.Number) End If
If CheckService("IMAService") = FALSE then wscript.echo "The Citrix IMA Service is not started... Exiting Script..." wscript.quit (2) End If
Set objLM = CreateObject("CPSCOMInterop.CPSLoadManager.1") Set objReturnValue = objLM objReturnValue = objLM.SetServerLMState(strComputer, DISABLELB)
If Err.Number then wscript.echo "Error: " & Err.Number wscript.quit (Err.Number) End If
wscript.quit(0)
Function CheckService(strService) CheckService = FALSE Set colServices = objSWbemServices.ExecQuery("SELECT * FROM Win32_Service where Name = '" & strService & "'") For Each objService In colServices CheckService = objService.Started wscript.echo " - Checking Service: " & objService.Name If CheckService then wscript.echo " - Service " & objService.Name & " Started" Else wscript.echo " - Service " & objService.Name & " Not Started" End if Next End Function
|