Description

Change Service Account Username & Password–PowerShell Script

This PowerShell script can be used to change the service account credential  remotely. 

Input – The input file (input.csv) contains server/computer name in the  following format.

Output – You will see the status on the screen as shown in the following screenshot:

More info - http://portal.sivarajan.com/

 

Script

PowerShell
Edit|Remove
# 
# Change service user name and password 
# www.sivarajan.com 
# 
clear 
$UserName = "Infralab\santhosh"  
$Password = "Password" 
$Service = "MpsSvc" #Change service name with your service name 
$Cred = Get-Credential #Prompt you for user name and password 
Import-CSV C:\Scripts\input.csv | % {  
$ServerN = $_.ServerName 
$svcD=gwmi win32_service -computername $ServerN -filter "name='$service'" -Credential $cred 
$StopStatus = $svcD.StopService() 
If ($StopStatus.ReturnValue -eq "0") # validating status - http://msdn.microsoft.com/en-us/library/aa393673(v=vs.85).aspx 
    {write-host "$ServerN -> Service Stopped Successfully"} 
$ChangeStatus = $svcD.change($null,$null,$null,$null,$null,$null,$UserName,$Password,$null,$null,$null) 
If ($ChangeStatus.ReturnValue -eq "0")  
    {write-host "$ServerN -> Sucessfully Changed User Name"} 
$StartStatus = $svcD.StartService() 
If ($ChangeStatus.ReturnValue -eq "0")  
    {write-host "$ServerN -> Service Started Successfully"} 
}