Powershell script to change service account

前端 未结 10 2359
小蘑菇
小蘑菇 2020-12-15 03:07

Does anyone have a Powershell script to change the credentials used by a Windows service?

10条回答
  •  既然无缘
    2020-12-15 03:32

    The given answers do the job.

    Although, there is another important detail; in order to change the credentials and run the service successfully, you first have to grant that user account permissions to 'Log on as a Service'.

    To grant that privilege to a user, use the Powershell script provided here by just providing the username of the account and then run the other commands to update the credentials for a service as mentioned in the other answers, i.e.,

    $svc=gwmi win32_service -filter 'Service Name'
    
    $svc.change($null,$null,$null,$null,$null,$null,'.\username','password',$null,$null,$null)
    

提交回复
热议问题