我已经看到很多用于手动停止/启动列表中的服务的脚本,但是我如何以编程方式生成该列表 - 只是 - 自动服务。我想编写一些重新启动脚本,并且正在寻找一种方法来验证所有应该正确启动的服务实际上是否正确启动。
问问题
15383 次
1 回答
11
Get-Service
返回System.ServiceProcess.ServiceController
不公开此信息的对象。因此,您应该将 WMI 用于此类任务:Get-WmiObject Win32_Service
. 显示所需的示例StartMode
并在 Windows 控制面板中格式化输出:
Get-WmiObject Win32_Service |
Format-Table -AutoSize @(
'Name'
'DisplayName'
@{ Expression = 'State'; Width = 9 }
@{ Expression = 'StartMode'; Width = 9 }
'StartName'
)
您对自动但未运行的服务感兴趣:
# get Auto that not Running:
Get-WmiObject Win32_Service |
Where-Object { $_.StartMode -eq 'Auto' -and $_.State -ne 'Running' } |
# process them; in this example we just show them:
Format-Table -AutoSize @(
'Name'
'DisplayName'
@{ Expression = 'State'; Width = 9 }
@{ Expression = 'StartMode'; Width = 9 }
'StartName'
)
于 2010-05-07T03:30:48.970 回答