如何获取可能的Windows服务状态列表?

时间:2018-09-27 10:04:23

标签: windows powershell

我正在使用Powershell脚本来卸载Windows服务。我希望它处理大多数(如果不是全部)可能的情况。在尝试卸载服务之前,我想检查的一件事是服务状态。

我找不到Windows服务可以具有的可能状态的完整列表。

除了明显的状态(“已停止/正在运行/正在停止”)之外,我还应该处理其他相关状态吗?

1 个答案:

答案 0 :(得分:2)

您可以通过对GetNames类型使用枚举System.ServiceProcess.ServiceControllerStatus方法来获取这些信息:

[enum]::GetNames([System.ServiceProcess.ServiceControllerStatus])

返回:

Stopped
StartPending
StopPending
Running
ContinuePending
PausePending
Paused