This script was the outcome of researching a way to automate the replacement of a local service account to manage the cluster service. This automation could be used to change any account for any service.
Note that the script logs the sequence as the script proceeds to the local event log -- this serves both as an audit requirement and as a diagnostic tool.
When changing out the service account, it does require stopping the Cluster Server service, be sure to change one node at a time to allow the cluster fail-over to take place. We sequenced the updates allowing one hour interval between cluster nodes.
ModifyServiceAccount.vbs
' Created by Steve Thompson
' v1.00
'
Option Explicit
Const EVENT_SUCCESS = 0
Const EVENT_FAILURE = 1
Const EVENT_WARNING = 2
Dim strComputer
Dim strAccount
Dim objWMIService
Dim colServiceList
Dim strErr
dim objShell
Dim strLogData
On error resume next
Set objShell = WScript.CreateObject("WScript.Shell")
strComputer = "."
' expects arguments passed as part of the command line
' arg1 - domain\account
' arg2 - password
strAccount = WScript.Arguments.Unnamed.Item(0)
strPassword = WScript.Arguments.Unnamed.Item(1)
' wscript.echo "strAccount= '" & strAccount & "'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name = 'ClusSvc'")
For each objService in colServiceList
if UCASE(objService.Name) = "CLUSSVC" Then
' stop service
objService.StopService()
strErr = err
strLogData = "Stop Service step -- '" & objService.Name & "'. Return Code('" & strErr & "')"
WriteEventLog EVENT_SUCCESS, strLogData
' wait
Wscript.Sleep 20000
' change out service account
strErr = objService.Change _
( , , , , , , strAccount, strPassword)
strErr = err
strLogData = "Change Service Account and password step -- " & "Return Code('" & strErr & "')"
WriteEventLog EVENT_SUCCESS, strLogData
' restart service
objService.StartService()
strErr = err
strLogData = "Re-start Service step -- '" & objService.Name & "Return Code('" & strErr & "')"
WriteEventLog EVENT_SUCCESS, strLogData
end if
Next
Sub WriteEventLog (zStatus, zData)
objShell.LogEvent zStatus, zData
End Sub