How can I extract “Path to executable” of all services with PowerShell

前端 未结 4 1139
猫巷女王i
猫巷女王i 2020-12-24 02:08
Get-Service *sql* | sort DisplayName | out-file c:/servicelist.txt

I have a one line PowerShell script to extract list of all services running on m

4条回答
  •  春和景丽
    2020-12-24 02:29

    I think you'll need to resort to WMI:

    Get-WmiObject win32_service | ?{$_.Name -like '*sql*'} | select Name, DisplayName, State, PathName
    

    Update If you want to perform some manipulation on the selected data, you can use calculated properties as described here.

    For example if you just wanted the text within quotes for the Pathname, you could split on double quotes and take the array item 1:

    Get-WmiObject win32_service | ?{$_.Name -like '*sql*'} | select Name, DisplayName, @{Name="Path"; Expression={$_.PathName.split('"')[1]}} | Format-List
    

提交回复
热议问题