Managing System Services Using Windows PowerShell

You can easily manage system services using Windows PowerShell by just typing some simple Cmdlets. Below are some of the examples that help you to manage system services using Windows PowerShell.

Getting all Services (Running and Stopped)

To get all the services ( Running and Stopped services), use Get-Service

Example 

PS C:\> Get-Service

[ This Cmdlet returns all the services (Running and Stopped) ]

Windows PowerShell

Note

If you look at BITS service, it is currently in “Stopped” Status

Starting a Service

As you know , BITS service is currently in a stopped state. To start this service, use Start-Service Cmdlet add the name of the service using -Name parameter

Example

PS C:\> Start-Service -Name BITS

Windows PowerShell

[ As you can notice above, Now BITS service is up and Running ]

Stopping a Service

To stop the BITS Service, use Stop-Service Cmdlet add the name of the service using -Name parameter

Example

PS C:\> Stop-Service -Name BITS

Windows PowerShell

Note

We successfully stopped BITS service.

Suspending a Service

To suspend or pause a service, use Suspend-Service Cmdlet

Example

PS C:\> Suspend-Service -Name BITS

Windows PowerShell

O
ops...! It gave me an error “BITS service cannot be suspended because this service does not support being suspended or resume”

Let us look at BITS Service object and figure out why we cannot suspend this service

Example

PS C:\> Get-Service BITS | Select *

Windows PowerShell

Note

CanPauseAndContinue Property value is False, so it cannot be suspended.

Note

We can only suspend a service if it has CanPauseAndContinue value TRUE. So let us look at other services that have CanPauseAndContinue value TRUE.

Example

PS C:\ > Get-Service | Where {$_. CanPauseAndContinue}

Windows PowerShell

As you see above, there are four services that have CanPauseAndContinue value TRUE. So let us Suspend one of these services

Example

PS C:\ >Suspend-Service - Name DNS

Windows PowerShell

If you notice in the above screenshot, we successfully suspended or paused DNS service

Restarting a Service

To Restart a Suspended or Paused service, use Restart-Service Cmdlet. In this example I am going to restart DNS service, as we know we just suspended it.

Example

PS C:\> Restart-Service -Name DNS

Windows PowerShell

As you can see above, DNS service is now Running.

Up Next
    Ebook Download
    View all
    Learn
    View all