Powershell Change Windows Service Password

Change

Jan 24, 2012  How to Change Windows Passwords with PowerShell. This is much faster because you can apply it to several machines at once with reusable code.

With this powershell script you will be able to change the user name and password of any Windows service. It can work against 1 or more services at the same time. The process will stop the service before changing the credentials and it will start it aftet. If the service is not running before the change, the service will not be started neither.

Pre-Requisites:

  1. The ps1 file should be executed elevated. If not the change method will fail.
  2. The account running the script must have:
Powershell
  • Rights to execute powershell
  • WMI Access (since we are accessing the win32_service class)

Functionalities

  • You can change the user name and password of 1 windows service or many.
  • it can interact with a remote server.

Parameters

Powershell Change Windows Service Password Reset

All parameters are mandatory. If you don’t provide them, powershell will ask you to provide them.

  • UserName: This would be the new user name. Examples:
    • .Administrator
    • DomainNameAdministrator
  • Password: this is the user password. If the password contains a $ you must pass the parameter enclosed in ‘’ (the symbol $ is not allowed in ps)
  • Service: This is the service name in which you want to change the credentials. WildCards characters are supported since the query is filtering using a like expression. Examples:
    • ‘MSSQLSERVER’
    • ‘BTSSVC%’ –> it will act over all BizTalk porcesses in the server
  • ServerN: Name of the server in which we want to change the service.
  • SecondsToWait: This is the time in seconds that the script will wait before starting the service again

Output:

This is an output example:

This was an attempt to change the user and password of all Windows services starting by MSSQL.

Examples:

  • Changing the user and pasword of all BizTalk host instances:

    .changeUser.ps1UserName .Administrator –Password admPwd –Service‘BTSSVC%’ServerN ServerA –SecondsToWait 2

Powershell Set Windows Service Password

  • Changing the user and pasword of the SQL Server Agent:

    .changeUser.ps1UserName .Administrator –Password admPwd –ServiceSQLSERVERAGENTServerN ServerA –SecondsToWait 2

Download the Code

You can download the code here, at MSDN Code Gallery.