What is Windows' equivalent of the "which" command in Unix? Is there an equivalent PowerShell command?

Solution 1:

Newer versions of Windows (I think Windows 2003 and up) have the where command:

C:\>where ping
C:\Windows\System32\PING.EXE

And for PowerShell, explicitly add the .exe suffix:

PS C:\>where.exe ping
C:\Windows\System32\PING.EXE

Solution 2:

Yes, Get-Command will find all commands including executables:

PS\> Get-Command ipconfig

If you want to limit the commands to just executables:

PS\> Get-Command -CommandType Application

Will find all exes in your path. There is an alias for interactive use:

PS\> gcm net* -CommandType Application

To get the path of an executable, you can use the Path property of the returned object. For example:

PS\> (Get-Command notepad.exe).Path

For more info, run man Get-Command -full.

Solution 3:

where.exe explicitly rather than where works for me in PowerShell:

PS C:\Users\birdc> where ping
PS C:\Users\birdc> where.exe ping
C:\Windows\System32\PING.EXE

Solution 4:

In addition to user10404, the help command will work on aliases, so you can use the same command name (gcm) for help and interactive use:

help gcm -Parameter *
# or
man gcm -Par *

Solution 5:

If you want to make it short, create a one line which.cmd file with the content

echo %~$PATH:1

This will search the first parameter (%1) fed to the script and display the full path of found file. Good place to put this script in windows 10 is %LOCALAPPDATA%\Microsoft\WindowsApps\which.cmd

And you get your which command in path.

c:\>which cmd.exe

c:\>echo C:\Windows\System32\cmd.exe
C:\Windows\System32\cmd.exe