Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell script to change service account

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

like image 816
Jesse Weigert Avatar asked Nov 24 '08 07:11

Jesse Weigert


People also ask

How do I change a service account in PowerShell?

In Powershell, we can change Windows Service Account username and password using WMI based powershell cmdlet Get-WmiObject and the WMI class Win32_Service. You can even easily change Service account infromation in Remote Computer.

How do I pass credentials in PowerShell without prompt?

$cred = Get-Credential without asking for prompts in powershell - Microsoft Tech Community.

How do I run a service account in PowerShell?

Open the Services snapin by executing services. msc . Find the PowerShell Universal service and right click it and then click Properties. Click the Log On tab and enter the credentials for the service account.

How do I rename a Windows service in PowerShell?

Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services and find the subkey with your service's name. Right-click the key you found in step #3, and select Rename. Enter the new name for the service. Restart the computer.


1 Answers

Bit easier - use WMI.

$service = gwmi win32_service -computer [computername] -filter "name='whatever'" $service.change($null,$null,$null,$null,$null,$null,$null,"P@ssw0rd") 

Change the service name appropriately in the filter; set the remote computer name appropriately.

like image 55
Don Jones Avatar answered Oct 03 '22 13:10

Don Jones