Powershell set username/pwd for windows services

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
enthuguyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kevinhsiehCommented:
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
Shaun VermaakTechnical SpecialistCommented:
$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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
enthuguyAuthor Commented:
Thanks kevinhsieh, yes it is a service account.

Thanks Shaun, will try this.

Is there a better way to handle/implement this pls?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.