In this post, I will show you how to query startup type (manual/automatic/disabled) of windows service on local or remote computer using Powershell and WMI.
Often people ask me why Get-Service is not returning Service startup type. That is Automatic/manual/disabled. I too don’t have a reason for that. But all I can say is, Get-Service is not tuned to give that information. The next question is how to query and what is the alternative.
The Win32_Service WMI class in Windows provides way to get this information. Most people neglect WMI and rely more on built-in cmdlets. While I don’t blame built-in cmdlets for anything, apart from limited functionality, I recommend using WMI or dotnet classes to get the information. They are fast, reliable, and the way is efficient.
Now let us move on to the original topic of how to query service startup type using Powershell and WMI. Since we decided to use WMI, use Get-WMIObject cmdlet to query the Win32_Service class.
Here is a small powershell script (Get-ServiceStartupType.ps1) which queries the startup type of given service.
[cmdletbinding()] param( [string[]]$Service, [switch]$Disabled, [switch]$Automatic, [switch]$Manual, [string]$ComputerName = $env:ComputerName ) foreach($Ser in $Service) { try { $Obj = Get-WmiObject -Class Win32_Service -Filter "Name='$Ser'" -ComputerName $ComputerName -ErrorAction Stop $Obj | select Name, DisplayName, StartMode } catch { Write-Error " Failed to get the information. More details: $_" } }
Examples:
- .\Get-ServiceStartupType.ps1 –Service Wsearch — queries the startup type of single service
- .\Get-ServiceStartupType.ps1 –Service Wsearch –ComputerName mypc1 — queries the startup type of single service on remote computer, mypc1.
- .\Get-ServiceStartupType.ps1 –ComputerName mypc1 – queries the startup type of all services on remote computer, mypc1.
- .\Get-ServiceStartupType.ps1 –Service Wsearch, wwansvc – queries the startup type of multiple services.
Output: