{"id":40,"date":"2008-09-08T22:44:45","date_gmt":"2008-09-08T13:44:45","guid":{"rendered":"http:\/\/www.jhouseconsulting.com\/index.php\/jhouseconsulting\/2008\/09\/08\/place-a-xenapp-server-in-and-out-of-service-the-easy-way\/"},"modified":"2008-10-21T01:00:02","modified_gmt":"2008-10-20T16:00:02","slug":"place-a-xenapp-server-in-and-out-of-service-the-easy-way","status":"publish","type":"post","link":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2008\/09\/08\/place-a-xenapp-server-in-and-out-of-service-the-easy-way-40","title":{"rendered":"Place a XenApp Server in and out of service the easy way"},"content":{"rendered":"<p>The new theory for placing a server off-line is to apply an &#8220;Out of service&#8221; load evaluator instead of disabling logons. The &#8220;Out of service&#8221; load evaluator consists of an empty Scheduling rule. The issue with this theory is that if you automate the move of a server into an &#8220;Out of service&#8221; load evaluator for maintenance, reboots, etc, then how do you know which load evaluator to move it back into when it&#8217;s ready to be placed back into production? I guess most would hard code this, or reference it from an ini file, etc, but that requires too much maintenance, as it can be difficult to manage in the larger farms that make use of different load evaluators across different hardware and load managed groups. So I enhanced the original version of this script to address this exact problem. It will read the existing load evaluator and write it against a registry value called PreviousLoadEvaluator under the HKLM\\SOFTWARE\\Citrix key. Then you can easily re-run this script with certain parameters to set the load evaluator back to what it was previously using. A simple concept that works very well.<!--more--><\/p>\n<p>For Example:<\/p>\n<p>To move a server into the &#8220;Out of service&#8221; load evaluator, run&#8230;<br \/>\ncscript.exe AttachLE.vbs &#8220;Out of service&#8221;<\/p>\n<p>To move a server back into its previous load evaluator, run&#8230;<br \/>\ncscript.exe AttachLE.vbs SetPrevious<\/p>\n<p>Enjoy!<\/p>\n<pre name=\"code\" class=\"vb.net\">\r\n'\r\n' Script name:\u00a0AttachLE.vbs\r\n'\r\n' Purpose:\u00a0Attaches a load evaluator to a Citrix server.\r\n'\r\n' Syntax:\u00a0AttachLE lename\r\n'\r\n'\u00a0\u00a0\u00a0 lename\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The load evaluator's name (case sensitive)\r\n'\r\n'---------------------------------------------------------------------------------------\r\n'\r\n' Based on a script written by Frank-Peter Schultze (http:\/\/www.fpschultze.de)\r\n'\r\n' Version 1.0 - Written by Jeremy@jhouseconsulting on 9th July 2008.\r\n' Version 1.1 - Updated by Jeremy@jhouseconsulting on 1st September 2008.\r\n'\r\n' For Example:\r\n'\r\n' To move a server into the \"Out of service\" load evaluator, run...\r\n'\u00a0\u00a0 cscript.exe AttachLE.vbs \"Out of service\"\r\n'\r\n' To move a server back into its previous load evaluator, run...\r\n'\u00a0\u00a0 cscript.exe AttachLE.vbs SetPrevious\r\n\r\n' More Examples:\r\n'\r\n' To move a server into the Default load evaluator run the following command...\r\n' cscript.exe AttachLE.vbs Default\r\n'\r\n' To move a server into the Advanced load evaluator run the following command...\r\n' cscript.exe AttachLE.vbs Advanced\r\n'\r\n'---------------------------------------------------------------------------------------\r\n\r\nOption Explicit\r\n\r\n' Note that the built-in Default load evaluator is MFDefaultLE, and the Advanced load evaluator is LMSDefaultLE.\r\nConst CTX_LE_DEFAULT\u00a0 = \"MFDefaultLE\"\r\nConst CTX_LE_ADVANCED = \"LMSDefaultLE\"\r\n\r\nDim strCitrixServer : strCitrixServer = \"\"\r\nDim strLEName\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : strLEName\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = \"\"\r\nDim WshNetwork\r\n\r\nCall GetArgs(strLEName)\r\n\r\nSet WshNetwork = WScript.CreateObject(\"WScript.Network\")\r\nstrCitrixServer = UCase(WshNetwork.ComputerName)\r\n\r\nIF strLEName = \"setprevious\" Then\r\n\u00a0 Call SetPreviousLE(strCitrixServer)\r\nElse\r\n\u00a0 Call GetCurrentLE(strCitrixServer)\r\n\u00a0 Call AttachLEToServer(strCitrixServer, strLEName)\r\nEnd If\r\n\r\nSet WshNetwork = Nothing\r\nwscript.quit(0)\r\n\r\nSub SetPreviousLE(strCitrixServer)\r\n\r\n\u00a0 Dim WshShell, strLEName, strKey, strValue\r\n\r\n\u00a0 Set WshShell = CreateObject(\"WScript.Shell\")\r\n\r\n\u00a0 strKey = \"HKLM\\SOFTWARE\\Citrix\"\r\n\u00a0 strValue = \"PreviousLoadEvaluator\"\r\n\r\n\u00a0 If RegValueExists(strKey &amp; \"\\\" &amp; strValue) Then\r\n\u00a0\u00a0\u00a0 strLEName = WshShell.RegRead(strKey &amp; \"\\\" &amp; strValue)\r\n\u00a0\u00a0\u00a0 wscript.echo \"The previous load evaluator was \" &amp; chr(34) &amp; strLEName &amp; chr(34)\r\n\u00a0 Else\r\n\u00a0\u00a0\u00a0 wscript.echo \"The previous load evaluator was not set. This script will exit.\"\r\n\u00a0\u00a0\u00a0 Set WshShell = Nothing\r\n\u00a0\u00a0\u00a0 Exit Sub\r\n\u00a0 End If\r\n\r\n\u00a0 Select Case LCase(strLEName)\r\n\u00a0\u00a0\u00a0 Case \"default\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 strLEName = CTX_LE_DEFAULT\r\n\u00a0\u00a0\u00a0 Case \"advanced\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 strLEName = CTX_LE_ADVANCED\r\n\u00a0\u00a0\u00a0 Case Else\r\n\u00a0 End Select\r\n\r\n\u00a0 Call AttachLEToServer(strCitrixServer, strLEName)\r\n\u00a0 WshShell.RegDelete(strKey &amp; \"\\\" &amp; strValue)\r\n\r\n\u00a0 Set WshShell = Nothing\r\nEnd Sub\r\n\r\nSub AttachLEToServer(strCitrixServer, strLEName)\r\n\r\n\u00a0 Dim objFarm\r\n\r\n\u00a0 On Error Resume Next\r\n\u00a0 Set objFarm = WScript.CreateObject(\"MetaFrameCOM.MetaFrameLoadEvaluator\")\r\n\u00a0 On Error GoTo 0\r\n\u00a0 If IsObject(objFarm) Then\r\n\u00a0\u00a0\u00a0 objFarm.LEName = strLEName\r\n\u00a0\u00a0\u00a0 objFarm.LoadData(True)\r\n\u00a0\u00a0\u00a0 objFarm.AttachToServerByName False, strCitrixServer\r\n\u00a0\u00a0\u00a0 objFarm.SaveData()\r\n\u00a0\u00a0\u00a0 Set objFarm = Nothing\r\n\u00a0\u00a0\u00a0 Select Case strLEName\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 Case \"MFDefaultLE\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 strLEName = \"Default\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 Case \"LMSDefaultLE\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 strLEName = \"Advanced\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 Case Else\r\n\u00a0\u00a0\u00a0 End Select\r\n\u00a0\u00a0\u00a0 wscript.echo \"The load evaluator for \" &amp; strCitrixServer &amp; \" has now been set to \" &amp; chr(34) &amp; strLEName &amp; chr(34)\r\n\u00a0 Else\r\n\u00a0\u00a0\u00a0 WScript.Echo \"Can not create MFCOM object.\"\r\n\u00a0 End If\r\n\u00a0 Set objFarm = Nothing\r\nEnd Sub\r\n\r\nSub GetCurrentLE(strCitrixServer)\r\n\r\n\u00a0 Dim WshShell, ServerObj, sCurrentLE, strCurrentValue, strKey, strValue\r\n\r\n\u00a0 Const MetaFrameWinSrvObject = 6\r\n\r\n\u00a0 Set WshShell = CreateObject(\"WScript.Shell\")\r\n\u00a0 Set ServerObj = CreateObject(\"MetaframeCom.MetaFrameServer\")\r\n\r\n\u00a0 ServerObj.Initialize MetaFrameWinSrvObject, strCitrixServer\r\n\r\n\u00a0 Set sCurrentLE=ServerObj.AttachedLE\r\n\u00a0 sCurrentLE.Loaddata(True)\r\n\r\n\u00a0 strCurrentValue=sCurrentLE.LEName\r\n\r\n\u00a0 Select Case strCurrentValue\r\n\u00a0\u00a0\u00a0 Case \"MFDefaultLE\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 strCurrentValue = \"Default\"\r\n\u00a0\u00a0\u00a0 Case \"LMSDefaultLE\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 strCurrentValue = \"Advanced\"\r\n\u00a0\u00a0\u00a0 Case Else\r\n\u00a0 End Select\r\n\r\n\u00a0 strKey = \"HKLM\\SOFTWARE\\Citrix\"\r\n\u00a0 strValue = \"PreviousLoadEvaluator\"\r\n\r\n\u00a0 WshShell.RegWrite strKey &amp; \"\\\" &amp; strValue, StrCurrentValue\r\n\r\n\u00a0 wscript.echo strCitrixServer &amp; \" is currently using the \" &amp; chr(34) &amp; StrCurrentValue &amp; chr(34) &amp; \" load evaluator\"\r\n\r\n\u00a0 Set WshShell = Nothing\r\n\u00a0 Set ServerObj = Nothing\r\nEnd Sub\r\n\r\nSub GetArgs(ByRef strLEName)\r\n\u00a0 Dim objArgs, strTmp\r\n\u00a0 Set objArgs = WScript.Arguments\r\n\u00a0 If (objArgs.Count = 1) Then\r\n\u00a0\u00a0\u00a0 strTmp = objArgs.Item(0)\r\n\u00a0\u00a0\u00a0 Select Case LCase(strTmp)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 Case \"default\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 strLEName = CTX_LE_DEFAULT\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 Case \"advanced\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 strLEName = CTX_LE_ADVANCED\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 Case \"setprevious\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 strLEName = \"setprevious\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 Case Else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 strLEName = strTmp\r\n\u00a0\u00a0\u00a0 End Select\r\n\u00a0 Else\r\n\u00a0\u00a0\u00a0 Call Usage(True)\r\n\u00a0\u00a0\u00a0 Exit Sub\r\n\u00a0 End If\r\nEnd Sub\r\n\r\nSub Usage(blnQuit)\r\n\u00a0 WScript.Echo \"Attaches a load evaluator to a Citrix server.\" &amp; VbCrlf &amp; VbCrlf &amp; _\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"Usage: \" &amp; WScript.ScriptName &amp; \" ''&lt;lename&gt;''\" &amp; VbCrlf &amp; VbCrlf &amp; _\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"Where lename is the load evaluator's name. It IS case sensitive\" &amp; VbCrlf &amp; _\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"and MUST be surrounded with double quotes if it contains spaces.\" &amp; VbCrlf\r\n\u00a0 If blnQuit Then WScript.Quit(0)\r\nEnd Sub\r\n\r\nFunction RegValueExists(sRegValue)\r\n' Returns True or False based of the existence of a registry value.\r\n\u00a0 Dim oShell, RegReadReturn\r\n\u00a0 Set oShell = CreateObject(\"WScript.Shell\")\r\n\u00a0 RegValueExists = True\u00a0 ' init value\r\n\u00a0 On Error Resume Next\r\n\u00a0 RegReadReturn = oShell.RegRead(sRegValue)\r\n\u00a0 If Err.Number &lt;&gt; 0 Then\r\n\u00a0\u00a0\u00a0 RegValueExists = False\r\n\u00a0 End if\r\n\u00a0 On Error Goto 0\r\n\u00a0 Set oShell = Nothing\r\nEnd Function\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The new theory for placing a server off-line is to apply an &#8220;Out of service&#8221; load evaluator instead of disabling logons. The &#8220;Out of service&#8221; load evaluator consists of an empty Scheduling rule. The issue with this theory is that if you automate the move of a server into an &#8220;Out of service&#8221; load evaluator &#8230; <a title=\"Place a XenApp Server in and out of service the easy way\" class=\"read-more\" href=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2008\/09\/08\/place-a-xenapp-server-in-and-out-of-service-the-easy-way-40\" aria-label=\"Read more about Place a XenApp Server in and out of service the easy way\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[73,5,38],"tags":[71,420,72],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-mfcom","category-scripting","category-xenapp","tag-load-eveluator","tag-mfcom","tag-out-of-service"],"aioseo_notices":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":1,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":53,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/40\/revisions\/53"}],"wp:attachment":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}