Prerequisite: Create a txt file with all the servers that are using a specific service account for one or more services. Create a column header of "servers" and just paste all the servers names below.You can compile this file from my earlier blogpost here.
Script:
$newpass = "ReallyLongPasswordYouWouldHateTyping"
Import-csv C:\data\computers.txt|foreach-object {
$server = $_.servers
$services = get-wmiobject win32_service -ComputerName $server |?{$_.Startname -like "*svcaccountname*"}
foreach($service in $services)
{$service.change($null,$null,$null,$null,$null,$null,$null,$newpass)
get-service $service.name -ComputerName $server|stop-service
start-sleep -s 30
get-service $service.name -ComputerName $server|start-service
}}
No comments:
Post a Comment