开发者

Checking only "Automatic" services with powershell

开发者 https://www.devze.com 2022-12-29 05:26 出处:网络
I\'ve seen lots of scripts out there for manually stopping/starting services in a list, but how can I generate that list programatically of -just- the automatic services. I want to script some reboots

I've seen lots of scripts out there for manually stopping/starting services in a list, but how can I generate that list programatically of -just- the automatic services. I want to script some reboots, and am looking for a way开发者_开发技巧 to verify that everything did in fact start up correctly for any services that were supposed to.


Get-Service returns System.ServiceProcess.ServiceController objects that do not expose this information. Thus, you should use WMI for this kind of task: Get-WmiObject Win32_Service. Example that shows the required StartMode and formats the output a la Windows control panel:

Get-WmiObject Win32_Service |
Format-Table -AutoSize @(
    'Name'
    'DisplayName'
    @{ Expression = 'State'; Width = 9 }
    @{ Expression = 'StartMode'; Width = 9 }
    'StartName'
)

You are interested in services that are automatic but not running:

# 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'
)
0

精彩评论

暂无评论...
验证码 换一张
取 消