StartType property added to Get-Service in PowerShell version 5 build 10586 on Windows 10 version 1511
If you've used PowerShell for more than 5 minutes, then you probably have some experience with the
Get-Service
cmdlet. As you could have guessed if you didn't already know, the Get-Service
cmdlet
retrieves information about Windows services.
Depending on what you're trying to accomplish, that particular cmdlet could leave a lot to be
desired. Want to know if a service is running? No problem. Want to know what the startup type is for
one or more services? Sorry, you can't accomplish that task with Get-Service
.
Notice that Get-Service
in PowerShell version 5 build 10240 on Windows 10 (and all prior operating
systems and PowerShell versions) doesn't include a StartType property:
1Get-Service -Name Dnscache | Select-Object -Property *
This wasn't due to a problem with the Get-Service
cmdlet as it simply returns what the .NET
Framework provides:
1[System.ServiceProcess.ServiceController]::GetServices() |
2Where-Object Name -eq Dnscache |
3Select-Object -Property *
That meant that you had to resort to querying WMI to determine if a service is set to start
automatically, manual, disabled, etc. This can be accomplished with either the Get-WMIObject
or
Get-CimInstance
cmdlet:
1Get-CimInstance -ClassName Win32_Service -Filter "Name = 'Dnscache'" -Property *
If you're running Windows 10 version 1511 (the updated version released in November of 2015), then
you're in luck because that particular version of PowerShell version 5 (build 10586) adds a
StartType property to Get-Service
:
1Get-Service -Name Dnscache | Select-Object -Property *
Once again, they are simply returning what the .NET Framework provides and this addition property is now included:
1[System.ServiceProcess.ServiceController]::GetServices() |
2Where-Object Name -eq Dnscache |
3Select-Object -Property *
As I've previously written, PowerShell version 5 adds a property to the Win32_Service WMI class that allows you to determine if a service is set to start automatically with a delayed start. If you're running a previous version of PowerShell, you'll have to query the registry for that info as demonstrated in this Hey, Scripting Guy! Blog article.
Stay tuned next week when I'll demonstrate how to determine if a service is set to start automatically with a trigger start. This is more difficult to determine than the delayed start ones and unfortunately there's no additions to newer operating systems or PowerShell versions to make it simpler.
µ