I am trying to find a service, stop it and then disable it remotely using Powershell. It can find and stop but cannot disable. For disabling, I have to run the Set-Service command separately. Can it be done in one line?
The following code-snippet will stop the Print Spooler service, but will not disable it:
$ip = "10.10.10.10" $svc_name = "Spooler" get-service -ComputerName $ip | Where-Object {$_.Name -eq $svc_name} | Stop-Service | Set-Service -StartupType Disabled The following code-snippet will stop and disable the Print Spooler service:
$ip = "10.10.10.10" $svc_name = "Spooler" get-service -ComputerName $ip | Where-Object {$_.Name -eq $svc_name} | Stop-Service Set-Service $svc_name -StartupType Disabled Powershell version is 5.1.14393.2969.
Edit: The following line will also find and disable. So, it looks like I can give two instructions with pipeline.
get-service -ComputerName $ip | Where-Object {$_.Name -eq $svc_name} | Set-Service -StartupType Disabled