'31 january 2011 version
'Inspired by
'http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/97c35d15-c7e1-4855-ae1b-81fd7352856b/
'http://msdn.microsoft.com/en-us/library/cc307934%28v=vs.85%29.aspx
'Script qui arrête les noeuds d un serveur NLB désigné
'Le script se connecte au serveur NLB indiqué, et lance par exemple la commande drainstop sur tous les noeuds du dit serveur, attend que le noeud soit effectivement stoppé afin que cela s arrête proprement.
'Examples de syntaxe :
'myscript.vbs -n "MyServerName" -c "drainstop"
'myscript.vbs -n "MyServerName" -c "start"
Dim strComputer
Dim strCommand
'Parse the command line.
call ParseCommand()
Wscript.Echo ""
Wscript.Echo "MicrosoftNLB_Node"
Wscript.Echo "================="
Wscript.Echo ""
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftNLB")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftNLB_Node",,48)
For Each objItem in colItems
Wscript.Echo "ComputerName: " & objItem.ComputerName
Wscript.Echo "DedicatedIPAddress: " & objItem.DedicatedIPAddress
Wscript.Echo "HostPriority: " & objItem.HostPriority
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "StatusCode: " & objItem.StatusCode
Wscript.Echo ""
If strCommand = "drainstop" Then
Wscript.Echo "Stopping the node"
ReturnValue = objItem.DrainStop()
bStart = true
Wscript.Echo "Waiting the node to stop..."
Wscript.Echo ""
While(bStart)
Set colItems1 = objWMIService.ExecQuery("Select StatusCode from MicrosoftNLB_Node",,48)
For Each objItem1 in colItems1
Call DisplayReturnValue(objItem1.StatusCode)
if objItem1.StatusCode = "1005" then
bStart = false
end if
Next
WScript.Sleep 1000
Wend
Wscript.Echo ""
Wscript.Echo "Node Stopped"
Wscript.Echo ""
End If 'If strCommand = "drainstop" Then
If strCommand = "start" Then
Wscript.Echo "Start the node"
objItem.Start()
End If
Next
sub DisplayReturnValue(ReturnValue)
'
' Translate the return value to a string and display it to output.
'
select case ReturnValue
case 1000
wscript.echo " Success."
case 1001
wscript.echo " Cluster mode is already stopped/started, or traffic handling is already enabled/disabled on specified port."
case 1002
wscript.echo " Cluster mode stop or start operation interrupted connection draining process."
case 1003
wscript.echo " Cluster mode could not be started due to configuration problems on the target host."
case 1004
wscript.echo " Port number not found among port rules."
case 1005
wscript.echo " Cluster mode is stopped on the host."
case 1006
wscript.echo " Cluster is converging."
case 1007
wscript.echo " Cluster or host converged successfully."
case 1008
wscript.echo " Host is converged as default host."
case 1009
wscript.echo " Host is draining after drainstop command."
case else:
wscript.echo " Unknown return (" & ReturnValue & ")."
end select
End Sub
Function ParseCommand()
'
' Parses the command line and fills the script variables
' with the appropriate values.
'
Dim ArgCount
Dim oArgs
Set oArgs = Wscript.Arguments
ArgCount = 0
if oArgs.Count = 0 then
wscript.echo "No arguments specified."
wscript.echo
call Help()
end if
While ArgCount < oArgs.Count
Select Case LCase(oArgs(ArgCount))
Case "-n"
ArgCount = ArgCount + 1
strComputer=LCase(oArgs(ArgCount))
wscript.echo "Server name : " & strComputer
Case "-c"
ArgCount = ArgCount + 1
strCommand=LCase(oArgs(ArgCount))
wscript.echo "Command : " & strCommand
Case Else:
wscript.echo "Invalid command."
wscript.echo
call Help()
wscript.quit
End Select
ArgCount = ArgCount + 1
Wend
End Function
sub Help()
'
' Display command-line syntax for the script.
'
wscript.echo "Stop/Start Network Load Balancing (NLB) service"
wscript.echo "Syntax:"
wscript.echo
wscript.echo "-n Server name or IP"
wscript.echo "-c command name : drainstop or start"
wscript.echo
wscript.echo "Examples:"
wscript.echo
wscript.echo "myscript.vbs -n ""MyServerName"" -c ""drainstop"""
wscript.quit
End Sub
Lien vers le fichier : cliquez ici