Checking only "Automatic" services with powershell

15,367

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'
)
Share:
15,367
Lee
Author by

Lee

Updated on June 04, 2022

Comments

  • Lee
    Lee almost 2 years

    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.