4

We are using ARR as reverse proxy and I would like to make a server unavailable for various reasons. How can this be done using Powershell?

Edit 1:
I found this http://blogs.iis.net/anilr/archive/2009/11/09/using-arr-config-extensibility-to-gracefully-stop-server.aspx tutorial for using JScript. But I'm not able to translate it to powershell.

Edit 2:
Using the Set-WebConfigurationProperty in WebAdministration module I'm able to changes settings for a server. I found SetState in %windir%\system32\inetsrv\config\schema\arr_schema.xml but I don't know how to invoke that method.

Carl Bergquist
  • 181
  • 1
  • 3
  • 7
  • I believe this link will be of help: http://forums.iis.net/t/1156563.aspx I've used it myself, and it works rather nicely. Matt – Matt Law Mar 18 '13 at 14:07

1 Answers1

3

Assuming your server farm is named myWebFarm and the server you're trying to set to drain is myNode1, the following PowerShell code will do the trick

Import-Module WebAdministration

$arr = Get-WebConfiguration -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter "webFarms/webFarm[@name='myWebFarm']/server[@address='myNode1']/applicationRequestRouting" 
$setState = $arr.Methods['SetState'].CreateInstance()
$setState.Input.Attributes['newState'].Value = 1
$setState.Execute()

If you want to check the value of currentRequests counter to see when it has finished draining (goes to 0), you can use

(Get-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter "webFarms/webFarm[@name='myWebFarm']/server[@address='myNode1']/applicationRequestRouting/counters" -Name "currentRequests").Value

In general, the Generate Script feature of Configuration Editor in the IIS Manager GUI can be helpful in generating PowerShell scripts to get you at least part way there.