Delete Windows Service in Powershell

Sometimes, we may need to remove Windows services installed on our PCs. For example, we may want to delete orphaned services left over after uninstalling the application running them, or you may want to delete Windows Services simply because you don’t need them.

This article discusses how to remove Windows services safely, and it is structured as follows – Section 1 discusses how to list installed services, Section 2 identifies services that are safe to remove without breaking your computer, and the last Section discusses how to remove the services we don’t want anymore.

Listing Installed Windows Services using PowerShell

The Get-Service cmdlet gets all the services in the computer. The cmdlet, by default, lists the services with three properties – Status, Name, and DisplayName.

Note that the Name property is an alias for ServiceName; therefore, we will use the two names interchangeably throughout the post. It is the property we will use most in this article to identify services.

You can also filter the services. The following commands filter items with the string “ssh” in them.

Heads up! What Services are Safe to Stop or Delete?

Windows services can be divided into two – Microsoft services and third-party.

Most Microsoft services are not safe to be stopped or uninstalled. Any attempt to do that can crash your PC (There are a few you can remove without a serious problem).

On the other hand, most third-party services can be removed without a big problem, but you need to be careful in a few cases (we will mention them shortly).

You can identify core Windows services and third-party ones using System Configuration App.

Search for the app on the Start Menu and open it.

On the app, select the Services tab on the navigation bar, and hide the Microsoft services by checking the box at the bottom of the page. Whatever remains on the list at this point are third-party services.

The only third-party services you should not remove or stop are the ones with the words intel, display, wireless, or graphics. Intel-tagged services control many core functions of your PC; wireless services are essential for running your wireless connections; display controls the monitor behavior, and graphics are essential for the workings of graphic cards – the GPUS.

Now that we know what is safe to remove, let’s learn how to delete what we don’t want.

Delete Windows Service in Powershell

There are two tools you can use in this case

  • sc command line tool, and
  • Get-WmiObject native cmdlet
  • Remove-Service cmdlet for PowerShell version 6 and above

Using the sc legacy command line utility to delete Windows service

The general syntax for removing Windows Service using sc.exe is given by:

where <service_name> is the Name of the service, not DisplayName.

Note: For older versions of PowerShell (tested on PowerShell 5.1.22), you may need to run the service control tool (sc) with the extension, that is, sc.exe. This is because sc is an alias for the Set-Content cmdlet on older PowerShell. In a newer PowerShell (tested on PowerShell 7.3.2), the alias is removed; therefore, you can simply use the command tool as sc.

Let’s identify the service we want to remove using Get-Service. In particular, let’s remove a PostgreSQL service.

Then we can delete the service using the sc command utility.

Note: You need to run PowerShell with Admin privileges to be able to delete a service with the sc tool; otherwise, you will get the following error.

[SC] OpenService FAILED 5:
Access is denied.

Output:

[SC] DeleteService SUCCESS

And use the following line on older PowerShell; you run

Use Get-WmiObject native cmdlet

Here is an example of deleting a service using this cmdlet

Delete Windows service using the Remove-Service cmdlet

Remove-Service is available on PowerShell 6.0 and later. You can use it with this simple syntax.

That works with the Name property only. If you want to use the DisplayName, you can use the following command.

In the command above, the Get-Service cmdlet is used to fetch services with the “Service Name” string on the DisplayName, then pipe the result to Remove-Service to be removed.

Conclusion

This article discussed removing a Windows Service using the sc command utility, Get-WmiObject native cmdlet, and Remove-Service cmdlet. The latter is only available on PowerShell 6.0 and newer.