Under PowerShell, Get-Command will find executables anywhere in $Env:PATH.
$ Get-Command eventvwr CommandType Name Definition ----------- ---- ---------- Application eventvwr.exe c:\windows\system32\eventvwr.exe Application eventvwr.msc c:\windows\system32\eventvwr.msc
And since powershell let's you define aliases, which can be defined like so.
$ sal which gcm # short form of `Set-Alias which Get-Command` $ which foo ...
PowerShell commands are not just executable files (.exe, .ps1, etc). They can also be cmdlets, functions, aliases, custom executable suffixes set in $Env:PATHEXT, etc. Get-Command is able to find and list all of these commands (quite akin to Bash's type -a foo). This alone makes it better than where.exe, which.exe, etc which are typically limited to finding just executables.
Finding executables using only part of the name
$ gcm *disk* CommandType Name Version Source ----------- ---- ------- ------ Alias Disable-PhysicalDiskIndication 2.0.0.0 Storage Alias Enable-PhysicalDiskIndication 2.0.0.0 Storage Function Add-PhysicalDisk 2.0.0.0 Storage Function Add-VirtualDiskToMaskingSet 2.0.0.0 Storage Function Clear-Disk 2.0.0.0 Storage Cmdlet Get-PmemDisk 1.0.0.0 PersistentMemory Cmdlet New-PmemDisk 1.0.0.0 PersistentMemory Cmdlet Remove-PmemDisk 1.0.0.0 PersistentMemory Application diskmgmt.msc 0.0.0.0 C:\WINDOWS\system32\diskmgmt.msc Application diskpart.exe 10.0.17... C:\WINDOWS\system32\diskpart.exe Application diskperf.exe 10.0.17... C:\WINDOWS\system32\diskperf.exe Application diskraid.exe 10.0.17... C:\WINDOWS\system32\diskraid.exe ...
Finding custom executables
Unlike UNIX, where executables are files with the executable (+x) bit set, executables on windows are files present in one of the directories specified in the $PATH env. variable whose filename suffixes are named in the $PATHEXT env. variable (defaults to .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL).
As Get-Command also honours this env. variable, it can be extended to list custom executables. e.g.
$ $Env:PATHEXT="$Env:PATHEXT;.dll;.ps1;.psm1;.py" # temporary assignment, only for this shell's process $ gcm user32,kernel32,*WASM*,*http*py CommandType Name Version Source ----------- ---- ------- ------ ExternalScript Invoke-WASMProfiler.ps1 C:\WINDOWS\System32\WindowsPowerShell\v1.0\Invoke-WASMProfiler.ps1 Application http-server.py 0.0.0.0 C:\Users\ME\AppData\Local\Microsoft\WindowsApps\http-server.py Application kernel32.dll 10.0.17... C:\WINDOWS\system32\kernel32.dll Application user32.dll 10.0.17... C:\WINDOWS\system32\user32.dll
See Get-Command for more options and examples.
whichcommand in standard Unix. The POSIX utility istype. The C Shell has a which command, and some systems have it as an external executable. For instance, on Debian Linux,whichcomes from a package calleddebutils. This externalwhichdoes not "see" shell built-ins, aliases or functions.typedoes; Bash'stypehas an option to suppress that and just do a path lookup.