我如何问PowerShell的东西在哪里?

例如,"which notepad",它根据当前路径返回notepad.exe运行的目录。


当前回答

试试这个例子:

(Get-Command notepad.exe).Path

其他回答

如果你有勺子,你可以安装一个直接克隆:

scoop install which
which notepad

看看这个PowerShell哪个。

这里提供的代码表明:

($Env:Path).Split(";") | Get-ChildItem -filter notepad.exe

我通常只输入:

gcm notepad

or

gcm note*

gcm是Get-Command的默认别名。

在我的系统上,gcm note*输出:

[27] » gcm note*

CommandType     Name                                                     Definition
-----------     ----                                                     ----------
Application     notepad.exe                                              C:\WINDOWS\notepad.exe
Application     notepad.exe                                              C:\WINDOWS\system32\notepad.exe
Application     Notepad2.exe                                             C:\Utils\Notepad2.exe
Application     Notepad2.ini                                             C:\Utils\Notepad2.ini

您将获得与您正在查找的内容相匹配的目录和命令。

试试这个例子:

(Get-Command notepad.exe).Path

我喜欢Get-Command |格式列表,或更短,使用别名的两个,只用于powershell.exe:

gcm powershell | fl

你可以找到这样的别名:

alias -definition Format-List

制表符补全使用gcm。

一次列出所有选项:

set-psreadlineoption -editmode emacs