Working with remote Windows services in PowerShell

Here’s how to list, start and stop Windows services on a remote computer using PowerShell:


# List all services on the remote computer

# Stop the service and wait for it to change status
$service = (new-object System.ServiceProcess.ServiceController('Service name',''))
$service.WaitForStatus('Stopped',(new-timespan -seconds 5))

# Start the service again

This can come in really handy in deployment scripts, etc.

(Parts of this post came from The PowerShell Guy).


Update: In the earlier version of this post I used new-object every time I needed a reference to the service. That’s not necessary, it’s much prettier to use a variable for the reference, so I have now updated the code.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.