How does powershell find variable paths? For example like this:
cmd: where node
C:\Windows\System32\where.exe
How does powershell find variable paths? For example like this:
cmd: where node
C:\Windows\System32\where.exe
Aside from running where.exe, I would use get-command instead of where.exe:
get-command notepad
gcm notepad # | ft -a
CommandType Name Version Source
----------- ---- ------- ------
Application notepad.exe 10.0.18362.693 C:\Windows\system32\notepad.exe
If you really don't like the where alias:
remove-item alias:where -force
Usually, when you invoke where.exe, it will first look in the current directory for the executable. Then it will search in the directories located in PATH Environment variable. And if any extension is not specified, it will search in the extensions for PATHEXT environment variable. So when you use where node
it will first search in current directory and PATH directories with enumerating all extension in PATHEXT like node.exe, node.bat, node.vbs etc. You can assign more directories to PATH Using setx PATH "%path%;Directory"
and to PATHEXT like setx PATHEXT "%pathext%;Extension
from command prompt. Also powershell has a where.exe native alternative:
(Get-Command node).Definition
Will expand to the full path of found "node" in known directories. This method also works in the same way as where.exe.
Also one thing I cannot understand how simply typing where in powershell worked. Where and ? Are aliases for where-object. So to execute where.exe you need to run & where.exe param_list
(Note: as @Compo said in the comments, if you search for a file named "node.txt", and if anything named "node.txt.exe" exists, then it will match "node.txt.exe" so beware of double-extensions.)