Solved

PowerShell script to change Username and password for log on as service (using domain account) on remote server

Posted on 2014-01-28
4
4,396 Views
Last Modified: 2015-04-19
I am fairly new to Powershell and need to write a script to change the username and password on remote servers that have services that are set to use "log on as" using a domain account.  Is there a way to check this and then set the username and password
0
Comment
Question by:CAD_SB
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
becraig earned 500 total points
Comment Utility
I wrote a fairly short script to reset and update service account passwords where service account matched the one provided.

The idea behind this script requires:
1) The service account you are looking for
2) The password you plan to change to in the AD
3) The list of servers you want to scan.

$acctname = "domain\user"
$svcpwd  = "password"
#Text file
$servers = (gc serverlist.txt) 
#from AD 
#Import-Module ActiveDirectory
#$servers = (Get-ADComputer -Filter *)

foreach ($server in $servers) 
{
#Query service
gwmi win32_service -computername $server | % { 
if ($_.StartName -eq $acctname)
{
$servicename = $_.Name
write-host "updating $servicename"
$svcnm = gwmi win32_service -computername $server -filter "name='$servicename'"
#Update Service
$svcnm.change($null,$null,$null,$null,$null,$null,"$UserName",$svcpwd,$null,$null,$null) 
#Stop Service
$svcnm.stopservice
#Start Service
$svcnm.startservice
}
}
}

Open in new window

0
 
LVL 28

Expert Comment

by:becraig
Comment Utility
I had previously inserted the wrong code snippet, find the correct one above.
0
 

Author Comment

by:CAD_SB
Comment Utility
perfect - thankyou
0
 

Expert Comment

by:BSAIT
Comment Utility
Is it possible to scan a remote server and select "all services" utilising the specific AD service account and change the password.
I would like to firstly reset the AD password account then select a server on the domain and reset the password for all services that use the specified service account?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now