如何提取“可执行文件的路径"?使用 PowerShell 的所有服务 [英] How can I extract "Path to executable" of all services with PowerShell

查看:31
本文介绍了如何提取“可执行文件的路径"?使用 PowerShell 的所有服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Get-Service *sql* | sort DisplayName | out-file c:/servicelist.txt

我有一个单行 PowerShell 脚本来提取本地机器上运行的所有服务的列表,现在,除了显示状态"、名称"和显示名称"之外,我还想显示 到可执行文件"

I have a one line PowerShell script to extract list of all services running on my local machine, now, in addition to displaying "Status", "Name" and "DisplayName" I also want to display "Path to executable"

推荐答案

我认为您需要求助于 WMI:

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.

例如,如果您只想要路径名的引号内的文本,您可以在双引号上拆分并获取数组项 1:

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

这篇关于如何提取“可执行文件的路径"?使用 PowerShell 的所有服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆