40

I can't seem to find anything about a Powershell equivalent of the where command from cmd. Should I just call it from cmd or is there something more elegant in PS?

migrated from serverfault.com Nov 14 '13 at 13:20

This question came from our site for system and network administrators.

37

Use the Get-Command commandlet passing it the name of the executable. It populates the Path property of the returned object (of type ApplicationInfo) with the fully resolved path to the executable.

# ~> (get-command notepad.exe).Path
C:\WINDOWS\system32\notepad.exe
  • 8
    If you find yourself using this a lot, you can abbreviate the command as gcm instead of typing the whole Get-Command word every time – Moshe Katz Nov 18 '13 at 20:38
  • @MosheKatz Thank you! gcm notepad has been working perfect for me when I just want to see which file am I calling. – Shawn Wang Jul 28 '17 at 18:07
  • And this, boys and girls, is how you over-complicate useful things that were already right. If it isn't broken, don't fix it. – AFP_555 Apr 18 '18 at 14:39
14

If you're just looking to have the same functionality without invoking cmd, you can call where.exe from powershell, as long as C:\Windows\System32 is in your path. The command where (without the .exe) is aliased to Where-Object, so just specify the full name.

PS C:\Users\alec> where
cmdlet Where-Object at command pipeline position 1
...

PS C:\Users\alec> where.exe
The syntax of this command is:

WHERE [/R dir] [/Q] [/F] [/T] pattern...
9

Get-ChildItem C:\SomeDir -Recurse *.dll

That's pretty much what the old where.exe does... was there more specific functionality that you're trying to mimic?

Edit: In response to Joshua's comment... oh, you want to search your PATH environment variables too? No problem.

Foreach($_ In $Env:Path -Split ';')
{
    Get-ChildItem $_ -Recurse *.dll
}
  • 1
    "where" also searches the PATH as well – Joshua McKinnon Nov 13 '13 at 0:38
  • 2
    oh, you want to search your PATH environment variables too? Um, yes, that’s the whole point to where, otherwise you can just use dir. Der. :-P – Synetech Nov 19 '13 at 2:26

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.