Let’s continue our exploration of using PowerShell to manage services. If you’ve missed the previous articles, take a few minutes to get caught up. In this article I want to explain how to configure services using the Set-Service cmdlet. This cmdlet uses the same service object that Get-Service works with.

Jeffery Hicks

Jeffery Hicks is a multi-year Microsoft MVP in Windows PowerShell, Microsoft Certified Professional and an IT veteran with 25 years of experience specializing in automation. He works today as an author, trainer and consultant.

Setting Remote Status ^

In Part 3, I explained that commands like Stop-Service lacked a –Computername parameter. You can use the commands in a remote session using Invoke-Command, which is still a great way especially if you are managing services on multiple computers. But we can also start, stop, restart, pause and resume services remotely using Set-Service.

This command supports –WhatIf and you’ll need to use –Passthru to get any objects written to the pipeline.

Valid values for –Status are running, stopped, and paused. Be aware that if a service has dependencies you might not be able to modify the service as you can see in the screenshot.

set-service - Cannot stop service

set-service - Cannot stop service

Unfortunately, Set-Service lacks the –Force parameter so in these situations you will have to resort to my remoting example using Invoke-Command. If you want to restart a service, you’ll need a pipelined expression like this:

Don’t forget to use –Passthru so an object is written to the pipeline, otherwise the second Set-Service command will have nothing to do.

Personally, I tend to run into more services that I can’t remotely stop using Set-Service, although starting is usually not a problem. I tend to stick using Invoke-Command. But remember, when using –Computername PowerShell is connecting using RPC and DCOM which can lead to firewall problems. Invoke-Command is using PowerShell remoting which you may not have configured or enabled anywhere, at least not yet!

Setting Startup Type ^

Where Set-Service comes in to play, is when you want to disable or enable a service using the –StartupType parameter. You can configure the service using the values Automatic, Manual or Disabled. Unfortunately, there isn’t an option for Automatic (Delayed).

However, there is no way to tell by looking at the service object what the startup type is.

There is a way, but I’ll cover that in the next article.

Be aware that changing the startup type doesn’t affect the current status of the service.

So if you want to disable and stop (or enable and start), pass the service object to the appropriate cmdlet.

Summary ^

Technically, Set-Service permits you to modify a service display name and description but I’ve never had a situation where I needed to do that. I primarily use Set-Service to enable and disable services. If I need to manage a service remotely, I using Invoke-Command.

Everything I’ve shown in the last few articles has been using a specific type of service objects which as you’ve seen has some limitations. In the next article we’ll explore other ways of working with services that get around these limitations.

Win the monthly 4sysops member prize for IT pros


1 Comment
  1. Vivek 1 year ago

    set-service -ComputerName kcmsdff-Status Stopped -PassThru | set-service <<<<  -PassThru -Status Running

    + CategoryInfo          : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Set-Service], ServiceCommandException

    + FullyQualifiedErrorId : CouldNotStartService,Microsoft.PowerShell.Commands.SetServiceCommand

    Can you resolve this ? Or Please explain me  the problem




Leave a reply

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



Please ask IT administration questions in the forum. Any other messages are welcome.

© 4sysops 2006 - 2017

Log in with your credentials


Forgot your details?

Create Account