Is there an equivalent of the DOS command “where” in PowerShell?

Posted: (EET/GMT+2)

 

In the old times, you might have used the CMD (aka DOS) command "where" to locate files along the PATH environment variable.

For example, if you wanted to know where "notepad.exe" is stored, you could have said "where notepad", and you would get the full path in return, usually "C:\Windows\System32\notepad.exe".

But in the PowerShell land, the "where" command is an alias to the command Where-Object, which serves a different purpose, and does not solve the problem.

However, PowerShell does have a command that is very much like the old "where". It is called Get-Command, and it can be used almost equally to "where".

The PowerShell command is more able than its older cousin, but it works well for simple needs. If you run a command like this:

get-command notepad

...you will get an output like this:

CommandType     Name           Version    Source
-----------     ----           -------    ------
Application     notepad.exe    10.0.16... C:\WINDOWS\system32\notepad.exe

You can further customize the output as follows:

get-command notepad | select Source

Happy scripting!