Lee*_*Lee 2 powershell windows-services reboot
我已经看到很多脚本用于在列表中手动停止/启动服务,但是如何以编程方式生成该列表 - 自动服务.我想编写一些重新启动的脚本,并且我正在寻找一种方法来验证事实上所有事情都确实正确启动了任何应该的服务.
Rom*_*min 11
Get-Service返回System.ServiceProcess.ServiceController不公开此信息的对象.因此,您应该将WMI用于此类任务:Get-WmiObject Win32_Service.示例显示StartModeWindows窗口控制面板的输出和格式:
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'
)
| 归档时间: | 
 | 
| 查看次数: | 14197 次 | 
| 最近记录: |