Three Cool PowerShell Service Tricks

Summary: Ed Wilson, the Microsoft Scripting Guy, talks about three cool Windows PowerShell tricks for working with services.

Microsoft Scripting Guy, Ed Wilson, is here. It does not matter what ones role is, whether an Exchange Server admin, a Group Policy guru, or even an ordinary every day power user, one eventually needs to work with services. Today I will show three cool tricks that involve using Windows PowerShell to work with services.

Stop multiple services at once

One of the nice features of the Get-Service cmdlet is that it accepts an array. Therefore, I can find information about specific services by supplying the name of multiple services. This technique is shown here.

PS C:\> Get-Service bits,wuauserv


Status   Name               DisplayName

------   ----               -----------

Running  bits               Background Intelligent Transfer Ser...

Running  wuauserv           Windows Update

The Stop-Service cmdlet accepts an array of ServiceController objects (the type of object returned by the Get-Service cmdlet). Therefore, I can pipe the results of the Get-Service cmdlet to the Stop-Service cmdlet to stop the array of services. This command is shown here.

Get-Service bits,wuauserv | Stop-Service

To see what a command does prior to the actual execution of the command, use the WhatIf switch. In the image that follows, the use of the WhatIf switch to prototype the command appears, followed by the actual command to stop the services.

Image of command output

Start multiple services

The Start-Service cmdlet also accepts an array of ServiceController objects as pipelined input. This means that I can use Get-Service to look at my service status, and then pipe the objects to the Start-Service cmdlet if required. This command is shown here.

Image of command output

Stopping and disabling services in one command

A cool thing is that I can use the Get-Service cmdlet to check on a group of services. If I want to stop them, I can pipe the returned ServiceController object to the Stop-Service cmdlet. But what if I also do not want the services to start up on the next reboot? Here is where some really cool stuff comes into play…

I use the PassThru switch, and the ServiceController objects will pass along the pipeline. I can then use those objects with the Set-Service cmdlet and change the startup type of the services to Disabled. Here is the command to accomplish this task.

Get-Service bits,wuauserv | Stop-Service -PassThru | Set-Service -StartupType disabled

Unfortunately, although Set-Service permits setting the startup type of the service to Disabled, the Get-Service cmdlet does not report the startup type of the service. To check on the results of our command, I need to use WMI. Here is the WMI command that I use to check the start mode of the services.

gwmi win32_service -filter "name = 'bits' OR name = 'wuauserv'"

The command and the associate output from the command are shown in the image that follows.

Image of command output

Join me tomorrow when I will talk about more way cool Windows PowerShell stuff.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

Comments (11)

  1. Much more useful than the older sc.exe and 'net stop' methods.

  2. jrv says:

    Justin C

    Use a transcript. or break the pipeline into a set of “foreach-object” sections and log to a file.

  3. Klaus Schulte says:

    Hi Ed,

    interestingly enough, we can work with multiple services in one command!

    That's something to keep in mind … using array parameters is often an option!

    Having followed and executed your 3 cool tricks, I would llike to add at least the fourth trick to it

    because you left us with two disabled and stopped services:

    4. "Enable and start multiple services in one command"

    Get-Service bits,wuauserv | Set-Service -StartupType automatic -PassThru | Start-Service

    I hope this helps 🙂


  4. ratty67 says:

    Why doesn't Get-Service return the startup type ?  Would have thought that a basic property ?

  5. Ed Wilson says:

    @Klaus Schulte thanks, yes starting two services back up is a good idea to do after disabling them. I appreciate the addition.

  6. Ed Wilson says:

    @ratty67 PowerShell does not return startup type via the Get-Service cmdlet because it relies on the ServiceController object from the .NET Framework. This class does not contain the information, and therefore the cmdlet does not return it. I am not sure why the ServiceController class does not contain the information.

  7. Walid Toumi says:


    you can use WMI instead of serviceController, or use this with PS3 to extend types directly:

    PS III> # untested:

    PS III> $props = @{

     TypeName =  'System.ServiceProcess.ServiceController'

     MemberName = 'StartUpMode'

     MemberType = 'ScriptProperty'

     Value = { (gwmi win32_service -filter "name='$($'").startMode }

     DefaultDisplayPropertySet = Status,Name,DisplayName,StartUpMode


    PS III> Update-TypeData @props

  8. Justin C says:

    how would i restart a service or list of services while taking the “Stopping Service” and “Starting Service” and sending it to a txt file like RestartServices.txt?

  9. Tom Sadler says:

    Quick question…
    How would this work for a service with an unusual service name? For example, the service I am working with is ECM Repository Service, and has a display name of ECM Dcocument Repository Service. With a service name that has so many spaces, it doesnt seem to
    recognise it. See below and thank yuou in advance 🙂

    PS H:> Get-Service ECM Repository Service
    Get-Service : A positional parameter cannot be found that accepts argument ‘Repository’.
    At line:1 char:12
    + Get-Service <<<< ECM Repository Service
    + CategoryInfo : InvalidArgument: (:) [Get-Service], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetServiceCommand

  10. michaelr says:

    Hi Tom, Try:
    Get-Service ‘ECM Repository Service’


  11. Tom Sadler says:

    Hi Michael,
    That took care of it. Thank you for your help on this 🙂

Skip to main content