Monday, February 3, 2014

Powershell: One Liner to output windows services and their StartMode

Here is a one line Powershell command to output the Windows services and their start-up type (Manual, Auto, Disabled).

Handy to check SOE images and ensure all those services are set consistently in between releases or simply take a dump of those settings on servers to keep track of things.

(Get-Service).name | %{@{$_=(Get-WmiObject -Class Win32_Service -Property StartMode -Filter "Name='$_'").StartMode}}




Edit: Here is a more advanced version of that one liner, with the display name and then the service name ( start-up type) - Service Status.
Notice the use of an hash table and -f option to format the output string and include several object properties.

Get-Service |%{@{$_.DisplayName='{0} ({1}) - {2}' -f $_.Name,(Get-WmiObject -Class Win32_Service -Property StartMode -Filter  "Name='$($_.Name)'").StartMode, $_.status}} | format-Table -AutoSize