I writing some scripts to start and stop some services remotely using powershell.
I'm running the following commands to do the task:
To get session :
$UserName = "IpAddress\username"
$Password = ConvertTo-SecureString "password" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($UserName, $Password)
$s = New-PSSession -ComputerName IpAddress -Credential $psCred
To stop the service :
Invoke-Command -Session $s -ScriptBlock {Stop-Service -Name "ServiceName" -Force}
These are working perfectly fine as expected.
Now my requirement is to set the start type of the service to delayedstart.For that I'm writing the below command:
Invoke-Command -Session $s -ScriptBlock {sc config "ServiceName" start=delayed-auto}
But this is giving error :
A positional parameter cannot be found that accepts argument 'start=delayed-auto'.
When start and stop commands are working, why is this not working? Am I missing anything here?