Checking only "Automatic" services with powershell

I have seen many scripts for manual stops / starts in the list, but how can I generate this list programmatically from free automatic services. I want to script some reboots, and I'm looking for a way to check that everything is indeed running correctly for whatever services it should have.

+2


a source to share


1 answer


Get-Service

returns System.ServiceProcess.ServiceController

objects that do not expose this information. Thus, you have to use WMI to such problems: Get-WmiObject Win32_Service

. An example that shows the required StartMode

and formats the output pane a la Windows:

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

      



You are interested in automatic but not started services:

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

      

+11


a source







All Articles