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,578 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 29

Accepted Solution

by:
becraig earned 500 total points
ID: 39816790
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 29

Expert Comment

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

Author Comment

by:CAD_SB
ID: 39855031
perfect - thankyou
0
 

Expert Comment

by:BSAIT
ID: 40732690
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
A procedure for exporting installed hotfix details of remote computers using powershell
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 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

856 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