如下说明是翻译: help Stop-Service 产生的帮助信息.
译者: Edengundam(马涛)
Stop-Service
大纲
停止一个或多个运行的服务.
语法
Stop-Service [-name] <string[]> [-include <string[]>] [-exclude <string[]>] [-force] [-passthru] [-whatIf] [-confirm] [<CommonParameters>]
Stop-Service -displayName <string[]> [-include <string[]>] [-exclude <string[]>] [-force] [-passthru] [-whatIf] [-confirm] [<CommonParameters>]
Stop-Service [-inputObject <ServiceController[]>] [-include <string[]>] [-exclude <string[]>] [-force] [-passthru] [-whatIf] [-confirm] [<CommonParameters>]
详细描述
Stop-Service cmdlet向Windows服务控制器(Service Controller)为每个指定的服务发送停止消息. 你可以通过服务名称或显示名称(display name)来指定需要挂起的服务. 你还可以使用参数InputObject传递你需要停止的服务对象(译者注: 例如使用Get-Service返回的对象或对象列表).
参数
-name <string[]>
指定需要被暂停的服务名称, 此参数接受通配符.
此参数可以在命令行忽略. 你既可以使用"-Name", 也可以使用其别名"-ServiceName", 甚至忽略此参数名.
强制参数?
|
true
|
参数位置?
|
1
|
默认值
|
|
允许从管道绑定输入?
|
true (根据值, 根据属性名)
|
允许通配符扩展?
|
true
|
-include <string[]>
只将指定的服务挂起. 此参数值用于限定Path参数. 输入一个路径元素或模式, 例如"s*"(此参数允许通配符).
强制参数?
|
false
|
参数位置?
|
named
|
默认值
|
|
允许从管道绑定输入?
|
false
|
允许通配符扩展?
|
true
|
-exclude <string[]>
忽略指定的服务. 此参数值用于限定Path参数.输入一个路径元素或模式, 例如"s*"(此参数允许通配符).
强制参数?
|
false
|
参数位置?
|
named
|
默认值
|
|
允许从管道绑定输入?
|
false
|
允许通配符扩展?
|
true
|
-force <SwitchParameter>
在不破坏安全前提下, 能够避免影响命令成功执行的限制条件.. 例如, Force也会停止依赖被停止服务的其他服务.
强制参数?
|
false
|
参数位置?
|
named
|
默认值
|
False
|
允许从管道绑定输入?
|
false
|
允许通配符扩展?
|
false
|
-passthru <SwitchParameter>
输出此命令创建的对象到管道中. 默认情况下, 此命令不会将对象输出到管道.
强制参数?
|
false
|
参数位置?
|
named
|
默认值
|
False
|
允许从管道绑定输入?
|
false
|
允许通配符扩展?
|
false
|
-displayName <string[]>
指定需要被暂停的服务名称, 此参数接受通配符.
强制参数?
|
true
|
参数位置?
|
named
|
默认值
|
|
允许从管道绑定输入?
|
false
|
允许通配符扩展?
|
true
|
-inputObject <ServiceController[]>
挂起通过ServiceController对象表示的服务. 输入一个包含对象的变量, 或者一个能够产生对象的命令或表达式.
强制参数?
|
false
|
参数位置?
|
named
|
默认值
|
|
允许从管道绑定输入?
|
true (ByValue)
|
允许通配符扩展?
|
false
|
-whatIf
描述执行此命令将会发生的现象, 不会真正执行此命令.
强制参数?
|
false
|
参数位置?
|
named
|
默认值
|
|
允许从管道绑定输入?
|
false
|
允许通配符扩展?
|
false
|
-confirm
执行命令前提示你进行确认.
强制参数?
|
false
|
参数位置?
|
named
|
默认值
|
|
允许从管道绑定输入?
|
false
|
允许通配符扩展?
|
false
|
<公共参数>
此命令支持公共参数: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. 更多信息, 输入, "get-help about_commonparameters".
输入类型
Object
注意
更多信息, 输入"Get-Help Stop-Service -detailed".需要技术信息, 输入"Get-Help Stop-Service -full".
如果需要为该命令提供多个参数, 请使用逗号进行分隔. 例如, "<parameter-name> <value1>, <value2>".
你可以使用Stop-Service内建别名"spsv". 需要更多信息, 查看 About_Alias.
Stop-Service只有在当前用户有权限时才能控制服务. 如果命令没有正常工作, 可能是您没有执行此操作的必要权限.
要查找您系统上服务的服务名称和显示名称, 输入命令"get-service". 服务名称显示在列名为"Name"的列中, 显示名称显示在列名为"DisplayName"的列中.
例1
C:/PS>stop-service sysmonlog
此命令停止本地计算机上的Performance Logs and Alerts (SysmonLog)服务.
例2
C:/PS>get-service -displayname telnet | stop-service
此命令停止本地计算机的Telnet服务. 此命令使用Get-Service cmdlet取得一个表示本地的Telnet服务的对象. 管道运算符将此命令结果传递给Stop-Service cmdlet, 此命令最终将会停止该服务.
例3
C:/PS>get-service iisadmin | format-list -property name, dependentservices
C:PS>stop-service iisadmin -force -confirm
Stop-Service停止本地的IISAdmin服务. 因为停止IISAdmin服务还会停止依赖它的其他服务, 所以最好在停止命令之前, 先查看依赖IISAdmin服务的的其他服务.
第一条命令将会列出那些依赖IISAdmin的服务. 它使用Get-Service cmdlet取得表示IISAdmin服务的对象. 管道运算符(|)将结果传递给Format-List cmdlet. 此命令通过指定Format-List的参数Property, 将IISAdmin服务的名称(Name)和依赖服务(DependentServices)属性显示出来.
第二条命令将会体制IISAdmin服务. 这里需要指定参数Force来停止依赖此服务的其他服务. 命令使用参数Confirm在停止每个服务之前提示您进行确认.
相关链接
Get-Service
Suspend-Service
Start-Service
Restart-Service
Resume-Service
Set-Service
New-Service