How to Work with Services in PowerShell

Services run many different aspects of Windows and are used for a great many tasks. How then can you use PowerShell to work with these services, whether it is existing services, creating new services, or to remove existing services? This article covers how PowerShell can be used to work services in Windows using PowerShell!

What built-in commands can we use PowerShell? Listing all the commands available in the Microsoft.PowerShell.Management module shows us the following.

These cover virtually all of the tasks that we would want in a service. Read on to learn how we can use these commands!

Retrieving and Manipulating Services in PowerShell

The first task that we need to tackle is how to enumerate and list all of the available services. Using the Get-Service command we can retrieve all known services or just one. Passing in a single service name allows us to find out the status of that service, such as the Print Spooler service of Windows.

Sponsored Content

Maximize Value from Microsoft Defender

In this ebook, you’ll learn why Red Canary’s platform and expertise bring you the highest possible value from your Microsoft Defender for Endpoint investment, deployment, or migration.

Get-Service -Name 'spooler'

What about listing all of the properties of a given service? Simply pipe the result into Select-Object * to see all of the available options.

Get-Service -Name 'spooler' | Select-Object *

There are a lot of properties that you would not typically be able to see using the GUI interface, notably some of the abilities such as CanPauseAndContinue.

Stopping, Starting, and Restarting a Service

To stop, start, and restart a service, the following commands are available to you.

  • Stop-Service – This will stop the service, but if there are dependent services, you will need to use the Force parameter switch.
  • Start-Service – Use this to start a service, provided it is of the start type of Manual, Automatic, or Automatic (Delayed Start). This will not work with Disabled services, but you can use Set-Service to change the start type first.
  • Restart-Service – This command will first stop the service and then start the service. If the service is already stopped it will start without notification. Use the Force parameter switch to stop the service with dependent services.
Stop-Service -Name 'spooler'
Start-Service -Name 'spooler'
Restart-Service -Name 'spooler'

If you do not have permission to a service, you will get an error that says: Cannot open 'service' service on computer '.'. Replace service with the expected service name, and . with the computer this is operating on, . indicates the local computer.

Creating a New Service

What if you have an executable that you want to run as a service? In the past, this used to be more difficult and required the use of the sc.exe command built-in to Windows. Using the New-Service command, you can quickly and easily create new Windows services, provided the executable you are targeting supports this.

$Params = @{
	'Name'           = 'TestService'
	'BinaryPathName' = 'C:\\Path\\To\\My\\executable.exe'
	'Description'    = 'This is a test service!'
	'StartupType'    = 'Automatic'
	'Credential'     = (Get-Credential)
	'DependsOn'      = 'NetLogon'

New-Service @Params

As you can see, it is pretty easy to create a new service. You can create the service with a startup type, credential, and even define a dependent service (or services, if passed an array).

Modifying a Service

What if you have an executable that you want to run as a service? In the past, this used to be more difficult and required the use of the sc.exe command built-in to Windows. Using the New-Service command, you can quickly and easily create new Windows services, provided the executable you are targeting supports this.

Set-Service -Name 'TestService' -Credentials (Get-Credential) -Status 'Stopped'

Sometimes mistakes are made, so how do we go about removing a service? Read on to learn more!

Removing a Service

Finally, you may find that you need to remove a service, which can be done using the appropriately named Remove-Service. This was introduced in PowerShell 6.0 and must be run as an administrator.

Remove-Service -Name 'TestService'

This command actually removes the service from both the services database and in the registry. There are two other service commands, which are not used often, so read on how you might use them!

Bonus! Suspending and Resuming a Service

There are certain services that can be suspended and then resumed using the Suspend-Service and Resume-Service commands. These commands only work on services that have $True set for the CanPauseAndContinue property. To find all of these services that support this, you can use the following command to find all that support this function.

Get-Service | Where-Object {$_.CanPauseAndContinue -eq $true} | Select-Object Name

For example, the LanmanWorkstation service supports this property.

Suspend-Service -Name 'LanmanWorkstation'
Resume-Service -Name 'LanmanWorkstation'

You may need to run your PowerShell session as an administrator to control the services if you receive an error when running against a supported service.


PowerShell over the years has introduced more ways to work with and manage Windows services. Although PowerShell 6+ is cross-platform, the support for managing services is not yet supported in all environments. Use the available commands to quickly and efficiently manage, create, and remove services on your systems today!

Related Topics:


Don't have a login but want to join the conversation? Sign up for a Petri Account

Comments (0)

Leave a Reply

Entrepreneur, hustler, husband, dad, Automator, content producer, published author, Microsoft MVP, DevOps pro and passionate problem-solver.
External Sharing and Guest User Access in Microsoft 365 and Teams

This eBook will dive into policy considerations you need to make when creating and managing guest user access to your Teams network, as well as the different layers of guest access and the common challenges that accompany a more complicated Microsoft 365 infrastructure.

You will learn:

  • Who should be allowed to be invited as a guest?
  • What type of guests should be able to access files in SharePoint and OneDrive?
  • How should guests be offboarded?
  • How should you determine who has access to sensitive information in your environment?

Sponsored by:

Live Webinar: Active Directory Security: What Needs Immediate Priority!Live on Tuesday, October 12th at 1 PM ET

Attacks on Active Directory are at an all-time high. Companies that are not taking heed are being punished, both monetarily and with loss of production.

In this webinar, you will learn:

  • How to prioritize vulnerability management
  • What attackers are leveraging to breach organizations
  • Where Active Directory security needs immediate attention
  • Overall strategy to secure your environment and keep it secured

Sponsored by: