It is always a nightmare for administrators to update the passwords of service accounts whenever they are changed. This script can help find the services using the account and update the password and restart the services.
Save he below code to ChangeSvcPwd.vbs and run by passing Server Name, Service User account and new password as parameters.
'---------------Script Start-------------
on error resume next
If Wscript.Arguments.Count < 3 Then
wscript.echo "Command Syntax: cscript ChangeSvcPwd.vbs Computername Username Password"
wscript.echo "Example: cscript ChangeSvcPwd.vbs server1 domain\user eRdc%90(m"
wscript.quit
End if
strComputer = WScript.Arguments(0)
strUser = WScript.Arguments(1)
strUser = replace(strUser,"\","\\")
strPassword = WScript.Arguments(2)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where StartName = '" & strUser & "'")
For Each objService in colListOfServices
wscript.echo "Changing password for service " & objService.name
errReturn = objService.Change( , , , , , , , strPassword)
wscript.echo "Trying to Stop service " & objService.name
errReturn = objService.StopService()
Wscript.Sleep 5000
wscript.echo "Trying to Start service " & objService.name
errReturn = objService.StartService()
Next
'-----------------------Script End---------------
Save he below code to ChangeSvcPwd.vbs and run by passing Server Name, Service User account and new password as parameters.
'---------------Script Start-------------
on error resume next
If Wscript.Arguments.Count < 3 Then
wscript.echo "Command Syntax: cscript ChangeSvcPwd.vbs Computername Username Password"
wscript.echo "Example: cscript ChangeSvcPwd.vbs server1 domain\user eRdc%90(m"
wscript.quit
End if
strComputer = WScript.Arguments(0)
strUser = WScript.Arguments(1)
strUser = replace(strUser,"\","\\")
strPassword = WScript.Arguments(2)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where StartName = '" & strUser & "'")
For Each objService in colListOfServices
wscript.echo "Changing password for service " & objService.name
errReturn = objService.Change( , , , , , , , strPassword)
wscript.echo "Trying to Stop service " & objService.name
errReturn = objService.StopService()
Wscript.Sleep 5000
wscript.echo "Trying to Start service " & objService.name
errReturn = objService.StartService()
Next
'-----------------------Script End---------------
No comments:
Post a Comment