I know this is an old thread, but I don’t see where anyone put all the pieces together.
The best answer is dispersed within all these answers, but no one says it with the proper combo.
The built in where.exe
gives you what you want (if your goal is to imitate the ‘nix version of which.)
PS aliases where to Where-Object
. But that isn’t a big deal if you are a ‘nix-head, you don’t typically use where. Maybe whereis
, but you are used to using which
(which is not part of PowerShell as a command or an alias).
So, just alias which to where.exe
. This provides the original ask and gives the look/feel of ‘nix without touching the default PS setup of where.
Also, it returns a string, so, be sure to account for multiple finds by splitting on the return character if needed.
Set-Alias -Name which -Value C:\Windows\System32\where.exe
Done.