Finding Services in PowerShell

by Oct 30, 2013

Get-Service lists all services on a computer, but the information returned is very sparse. You cannot easily see what a service does, whether it is a Microsoft or third-party service, and which executable runs the service.

With a little bit of data consolidation, you can get a lot more information. Here's a function called Find-Service that returns a wealth of information that should enable you to easily identify the service you are after:

function Find-Service
        $Name = '*',
        $DisplayName = '*',
    $pattern = '^.*\.exe\b'

    $Name = $Name.Replace('*','%')
    $DisplayName = $DisplayName.Replace('*','%')

    Get-WmiObject -Class Win32_Service -Filter "Name like '$Name' and DisplayName like '$DisplayName'"|
      ForEach-Object {

        if ($_.PathName -match $pattern)
            $Path = $matches[0].Trim('"')
            $file = Get-Item -Path $Path
            $rv = $_ | Select-Object -Property Name, DisplayName, isMicrosoft, Started, StartMode, Description, CompanyName, ProductName, FileDescription, ServiceType, ExitCode, InstallDate, DesktopInteract, ErrorControl, ExecutablePath, PathName
            $rv.CompanyName = $file.VersionInfo.CompanyName
            $rv.ProductName = $file.VersionInfo.ProductName
            $rv.FileDescription = $file.VersionInfo.FileDescription
            $rv.ExecutablePath = $path
            $rv.isMicrosoft = $file.VersionInfo.CompanyName -like '*Microsoft*'
            Write-Warning ("Service {0} has no EXE attached. PathName='{1}'" -f $_.PathName)
 Find-Service | Out-GridView  

Twitter This Tip! ReTweet this Tip!