Change Service Account Password

Ever wanted to automatically change the Password a service uses to log on to its account? WMI has a solution. Have a look:

$localaccount = ".\sample-de-admin-local"
$newpassword = "secret@Passw0rd"
$service = Get-WmiObject win32_Service -Filter "Name='Spooler'"
$service.Change($null,$null,$null,$null,$null,$null, `
$localaccount, $newpassword)

These lines assign a new User Account and Password for the Spooler service. Note that your account will need special privileges to be able to do that. If you get an "access denied" error, open services.msc and try to change the account manually using the GUI. You will get a message if your account lacks the necessary privileges and the privileges are added.

Twitter This Tip! ReTweet this Tip!


Posted Dec 16 2009, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.