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,649 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
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…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

733 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