Sample Header Ad - 728x90

unable to update service account password for windows service on remote database server

0 votes
1 answer
88 views
I am trying to update service account password for windows service(example: SQL service) on remote server but keeps getting following error. I am using **PowerShell version 7.0** which supports -Credential as parameter for Set-Service Error: >Set-Service: A parameter cannot be found that matches parameter name 'Credential'. Script:
$servers = Get-Content "C:\folder\servers.txt"

$ServiceName = read-host "Enter Service Name Here"

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

foreach ($server in $servers){
Invoke-Command -ComputerName $server -ScriptBlock {
get-service $using:ServiceName | stop-service 
$svc = Set-Service -Name $using:ServiceName -Credential $using:Cred
if ($svc)
{$OUT = "$Using:server Service Account Password Change Succeed"
$OUT}
else {$OUT = "$Using:server Service Account Password Change Failed"
$OUT}
Start-Sleep -Seconds 5
get-service $using:ServiceName | Start-service
}}
Asked by SqlDBA (171 rep)
Oct 7, 2024, 03:06 PM
Last activity: Oct 8, 2024, 01:47 AM