Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 30 down vote accepted

This was asked and answered on Stack Overflow: Equivalent of *Nix ‘which’ command in Powershell?

The very first alias I made once I started customizing my profile in powershell was 'which'.

New-Alias which get-command

To add this to your profile, type this:

"`nNew-Alias which get-command" | add-content $profile

The `n is to ensure it will start as a new line.

share|improve this answer
Exactly what I was looking for. thanks! – Herms Sep 2 '09 at 19:17

As of PowerShell 3.0, you can do

(Get-Command cmd).Path

Which also has the benefit over vanilla Get-Command of returning a System.String so you get a clean *nixy single line output like you may be used to. Using the gcm alias, we can take it down to 11 characters.

(gcm cmd).Path
share|improve this answer
If 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, try Get-Command where. – jpmc26 May 30 '14 at 17:14
This 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 Jul 12 '15 at 23:31
function which([string]$cmd) {gcm -ErrorAction "SilentlyContinue" $cmd | ft Definition}
share|improve this answer

Also answered in 2008: Is there an equivalent of 'which' on windows?

Try the where command if you've installed a Resource Kit:

Most important parts of the answer:

Windows Server 2003 and later provide the WHERE command which does some of what which does, though it matches all types of files, not just executable commands.


In Windows PowerShell you must type where.exe.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .