I want to update the password of all the services running under one account on multiple servers using powershell. i tried Get-process, Get-WMIObject cmdlets, but these two commands don't have serviceaccount usage. is there a way to update password of all the services running with an account by passing service account,password as parameters to the script.
To get list of services using a particular account you can do:
Get-WmiObject "win32_service" -Filter "StartName='domain\\user'"
To change the password for these, you can do:
Get-WmiObject "win32_service" -Filter "StartName='domain\\user'" |
%{$_.StopService();$_.Change($null,$null,$null,$null,$null,$null,$null,"blah");}
From here: http://www.send4help.net/change-remote-windows-service-credentials-password-powershel-495
try this:
Function GLOBAL:GET-PROCESSUSER ( $ProcessID ) {
(GET-WMIOBJECT win32_process –filter “Handle=$ProcessID”).GetOwner().User
}
$svcs = Get-Process | Select-Object name, starttime, ID
$a = @()
foreach ($svc in $svcs)
{
if ( $svc.name -ne "Idle" -and $svc.name -ne "System")
{
$al = New-Object System.Object
$al | Add-Member -type NoteProperty -name Name -Value $svc.name
$al | Add-Member -type NoteProperty -name Owner -Value ( get-processuser $svc.id)
$a += $al
}
}
$a
Edit after comment:
$a = (GET-WMIOBJECT win32_service) | ? { $_.startname -eq "domain\\username"} | %{$_.StopService();$_.Change($null,$null,$null,$null,$null,$null,$null,"newpassword");}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With