![](/img/trans.png)
[英]Powershell to display all automatic services that are stopped and attempt to start those services
[英]Checking only “Automatic” services with powershell
我已经看到很多脚本用于在列表中手动停止/启动服务,但是如何以编程方式生成该列表 - 自动服务。 我想编写一些重新启动的脚本,并且我正在寻找一种方法来验证事实上所有事情都确实正确启动了任何应该的服务。
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'
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.