If you’re working on Windows and using PowerShell, you’ve likely encountered situations where you need to find the exact location of an executable file on your system.
This tutorial will guide you through multiple methods to find the location of an executable using PowerShell. I will explain step by step.
When you type a command like notepad or git in PowerShell, Windows searches for the executable in directories listed in the PATH environment variable. The first matching executable found is run.
To find the location of the executable, you can mimic or query this search process using PowerShell commands.
Method 1: Using Get-Command
The most recommended way in PowerShell to find the location of an executable is by using the Get-Command cmdlet.
Syntax
Here is the syntax of the Get-Command cmdlet.
Get-Command <executable_name>Example
Below is an example.
Get-Command notepadOutput
CommandType Name Version Source
----------- ---- ------- ------
Application notepad.exe 10.0.19041 windows\system32\notepad.exeHere is the exact output in the screenshot below:

To get just the full path, use:
(Get-Command notepad).PathOutput:
C:\Windows\System32\notepad.exeGet-Commandsearches for commands, aliases, functions, and executables.- The
.Pathproperty returns the full path of the executable file.
This method works for any executable available in your system’s PATH.
Check out Get Last Reboot Time Using PowerShell
Method 2: Using where.exe
Windows includes a command-line utility called where.exe which locates executables in the PATH. You can invoke it from PowerShell.
Syntax
where.exe <executable_name>Example
where.exe notepadOutput
C:\Windows\System32\notepad.exe
C:\Windows\notepad.exe
C:\Users\fewli\AppData\Local\Microsoft\WindowsApps\notepad.exeHere is the exact output in the screenshot below:

Notes
- Unlike
Get-Command,where.execan return multiple paths if multiple versions of the executable exist in different PATH locations. - You must use
where.exeand not justwherein PowerShell becausewhereis an alias forWhere-Objectcmdlet.
Check out Find SQL Server Instances using PowerShell
Method 3: Using [System.Environment]::GetEnvironmentVariable(“PATH”)
If you want to manually search for an executable in the directories listed in your PATH environment variable, you can use this approach.
Step 1: Get the PATH variable
$pathDirs = [System.Environment]::GetEnvironmentVariable("PATH").Split(';')Step 2: Loop through each directory and check if the executable exists
$exeName = "notepad.exe"
foreach ($dir in $pathDirs) {
$fullPath = Join-Path -Path $dir -ChildPath $exeName
if (Test-Path $fullPath) {
Write-Output $fullPath
}
}- This script splits the PATH into individual directories.
- Checks each directory for the existence of the executable.
- Returns all matching paths.
This method is more manual but gives you full control and understanding of how Windows searches for executables.
Read PowerShell Get-WindowsAutoPilotInfo
Method 4: Using Get-Command with Aliases and Functions
Sometimes, the command you run is an alias or function, not a direct executable. To find the actual executable location, ensure you get the command type.
Get-Command <command_name> | Format-List Name, CommandType, Definition, PathExample:
Get-Command ls | Format-List Name, CommandType, Definition, PathOutput might show that ls is an alias for Get-ChildItem, which is a cmdlet, not an executable.
For executables, the CommandType will be Application and the Path will be the physical executable path.
Check out Enable BitLocker with PowerShell
Method 5: Using where.exe with Multiple Executables
If you want to find all instances of an executable:
where.exe pythonOutput might be:
C:\Python39\python.exe
C:\Users\YourName\AppData\Local\Microsoft\WindowsApps\python.exeThis helps identify which versions are installed and their locations.
Conclusion
In this tutorial, I explained different methods to find the location of executables in PowerShell.
| Method | Command Example | Description |
|---|---|---|
| Get-Command | (Get-Command notepad).Path | Returns the full path of the executable |
| where.exe | where.exe notepad | Lists all matching executable paths |
| Manual PATH scan | Script looping through PATH dirs | Custom search for executable |
| Get-Command info | Get-Command ls | Shows if the command is alias, function or an executable |
You may also like the following tutorials:
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.