Remove-Service
Removes a Windows service.
Syntax
Name (Default)
Remove-Service
[-Name] <String>
[-WhatIf]
[-Confirm]
[<CommonParameters>]
InputObject
Remove-Service
[-InputObject <ServiceController>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
The Remove-Service cmdlet removes a Windows service in the registry and in the service database.
The Remove-Service cmdlet was introduced in PowerShell 6.0.
Examples
Example 1: Remove a service
This removes a service named TestService.
Remove-Service -Name "TestService"
Example 2: Remove a service using the display name
This example removes a service named TestService. The command uses Get-Service to get an object
that represents the TestService service using the display name. The pipeline operator (|) pipes
the object to Remove-Service, which removes the service.
Get-Service -DisplayName "Test Service" | Remove-Service
Parameters
-Confirm
Prompts you for confirmation before running the cmdlet.
Parameter properties
| Type: | SwitchParameter |
| Default value: | False |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | cf |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-InputObject
Specifies ServiceController objects that represent the services to remove. Enter a variable that contains the objects, or type a command or expression that gets the objects.
The InputObject parameter doesn't enumerate collections. If a collection is passed, an error is thrown. When working with collections, pipe the input to enumerate the values.
Parameter properties
| Type: | ServiceController |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
InputObject
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | True |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-Name
Specifies the service names of the services to remove. Wildcard characters are permitted.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | True |
| DontShow: | False |
| Aliases: | ServiceName, SN |
Parameter sets
Name
| Position: | 0 |
| Mandatory: | True |
| Value from pipeline: | True |
| Value from pipeline by property name: | True |
| Value from remaining arguments: | False |
-WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Parameter properties
| Type: | SwitchParameter |
| Default value: | False |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | wi |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Inputs
System.ServiceProcess.ServiceController, System.String
You can pipe a service object or a string that contains the name of a service to this cmdlet.
Outputs
None
This cmdlet does not return any output.
Notes
To run this cmdlet, start PowerShell by using the Run as administrator option.