76
19
Does PowerShell have an equivalent to the which
command found in most (if not all) Unix shells?
There are a number of times I'd like to know the location of something I'm running from the command line. In Unix I just do which <command>
, and it tells me. I can't find an equivalent in PowerShell.
1This should be the accepted answer as it actually tells you what is the Powershell equivalent of the *NIX command
where
rather than teaching you how to set aliases on Powershell, which is not the title of the question. – mastazi – 2015-07-12T23:31:52.8303@mastazi: But that fails for builtins, which is a regression compared to e.g. zsh's
which
. (where
, by the way, is actually a Windows utility that can do a number of different things, one of which roughly approximates searching for a command along thePATH
.) Also, there's nothing wrong with an answer that explains how to do what was asked and also another, slightly more involved thing built on that. – SamB – 2017-11-29T23:04:45.7604If
Get-Command
finds multiple results, it returns an array. Additionally, if the command it finds is not an executable,Path
is undefined ($null
). This makes the answer here impractical for general use without heavy modification. For a good example of both these cases, tryGet-Command where
. – jpmc26 – 2014-05-30T17:14:59.547