Powershell set username/pwd for windows services

enthuguy
enthuguy used Ask the Experts™
on
Hi Powershell experts,

Using Powershell, would like to set username/password for a list of services (service1, service2, service3, etc) in Windows 2016 servers.
Since, I will be invoking this from AWS CloudFormation, Is there a better way to handle the password pls?
after setting credentials on these services, we need to ensure it is running as well.  :)

please help

Thanks in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
kevinhsiehNetwork Engineer

Commented:
You should be using Managed Service Accounts or Group Managed Service Accounts for handling credentials of services.

https://docs.microsoft.com/en-us/windows-server/security/group-managed-service-accounts/group-managed-service-accounts-overview
Technical Specialist
Awarded 2017
Distinguished Expert 2018
Commented:
$account="domain\user"
$password="passsword"
$service="name='servicename'"

$svc=gwmi win32_service -filter $service
$svc.StopService()
$svc.change($null,$null,$null,$null,$null,$null,$account,$password,$null,$null,$null)
$svc.StartService()

Open in new window

https://stackoverflow.com/questions/313622/powershell-script-to-change-service-account

Author

Commented:
Thanks kevinhsieh, yes it is a service account.

Thanks Shaun, will try this.

Is there a better way to handle/implement this pls?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial