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,730 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
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…

726 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