Remove-Service

Removes a Windows service.

语法

Name (默认值)

Remove-Service
    [-Name] <String>
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

InputObject

Remove-Service
    [-InputObject <ServiceController>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

说明

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.

示例

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

参数

-Confirm

Prompts you for confirmation before running the cmdlet.

参数属性

类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False
别名:cf

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值: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.

参数属性

类型:ServiceController
默认值:None
支持通配符:False
不显示:False

参数集

InputObject
Position:Named
必需:False
来自管道的值:True
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Name

Specifies the service names of the services to remove. Wildcard characters are permitted.

参数属性

类型:String
默认值:None
支持通配符:True
不显示:False
别名:ServiceName, SN

参数集

Name
Position:0
必需:True
来自管道的值:True
来自管道的值(按属性名称):True
来自剩余参数的值:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

参数属性

类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False
别名:wi

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值: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.

输入

ServiceController

You can pipe a service object to this cmdlet.

String

You can pipe a string that contains the name of a service to this cmdlet.

输出

None

This cmdlet returns no output.

备注

This cmdlet is only available on Windows platforms.

To run this cmdlet, start PowerShell by using the Run as administrator option.