How to pull physical path of a Windows Service using Get-Service command
Even with PowerShell 3, I don't see a way to get it with Get-Service.
This 1-liner will get you the pathname, albeit with a little less of the preferred "filter left" behavior:
gwmi win32_service|?{$_.name -eq "AxInstSV"}|select pathname
Or, if you want just the string itself:
(gwmi win32_service|?{$_.name -eq "AxInstSV"}).pathname
I wanted to do something similar, but based on searching / matching the path of the process running under the service, so I used the classic WMI Query syntax, then passed the results through format-table:
$pathWildSearch = "orton";gwmi -Query "select * from win32_service where pathname like '%$pathWildSearch%' and state='Running'" | Format-Table -Property Name, State, PathName -AutoSize -Wrap
You're welcome to turn this into a one-liner by skipping defining and passing $pathWildSearch, or you could just back gwmi statement up to continue after the semi-colon.
@alroc did good, but there's no reason to filter all services. Querying WMI is like querying a DB, and you can just ask WMI to do the filtering for you:
(Get-CimInstance Win32_Service -Filter 'Name = "AxInstSV"').PathName
To explore all of the meta available for that service:
Get-CimInstance Win32_Service -Filter 'Name = "AxInstSV"' | Select-Object *