Setting Service Account on Remote Machine

Hi All,

I have several hundred servers that I need to update service accounts on. Looking at the Set-Service command I do not have ‘-Credential’ as an option when using Invoke command to target remote host.

$Cred = Get-Credential
$Username = $Cred.username
$Password = $Cred.GetNetworkCredential().password

$S = Get-Service -Name myservice
Invoke-Command -ComputerName mycomputername -Credential $Cred -ScriptBlock {
Set-Service -Name $S -Credential $Cred

Try this. The Using: scope modifier can use local variables when running remote commands.

$serverlist = get-content \\path\to\serverlist.txt
$Cred = Get-Credential
$Username = $Cred.username
$Password = $Cred.GetNetworkCredential().password

Invoke-Command -ComputerName $serverlist -Credential $Cred -ScriptBlock {
Set-Service -Name myservice -Credential $Using:Cred

And for my clarification, you mention “Service Accounts”. To me, that is not the same as a “Service” which is what you appear to be trying to manipulate.

Additionally, Set-Service requires some parameters as the cmdlet is used to change properties on a service. Am I missing something here?


We have Windows Services running under the context of a domain account. The passwords for these accounts need to change. When this is done in AD I also need to update the Windows service to reflect the new password.

I get this error when I try that.

A parameter cannot be found that matches parameter name ‘Credential’.
+ CategoryInfo : InvalidArgument: (:slight_smile: [Set-Service], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.SetServiceCommand
+ PSComputerName : computername

Thanks for the clarification.

Have a look at Set-Service. -Credential was not added until Powershell 6. What version are you on?