PowerShell Find Location of Executable

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 notepad

Output

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     notepad.exe                                        10.0.19041 windows\system32\notepad.exe

Here is the exact output in the screenshot below:

PowerShell Find Location of Executable

To get just the full path, use:

(Get-Command notepad).Path

Output:

C:\Windows\System32\notepad.exe
  • Get-Command searches for commands, aliases, functions, and executables.
  • The .Path property 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 notepad

Output

C:\Windows\System32\notepad.exe
C:\Windows\notepad.exe
C:\Users\fewli\AppData\Local\Microsoft\WindowsApps\notepad.exe

Here is the exact output in the screenshot below:

Find Location of Executable PowerShell

Notes

  • Unlike Get-Commandwhere.exe can return multiple paths if multiple versions of the executable exist in different PATH locations.
  • You must use where.exe and not just where in PowerShell because where is an alias for Where-Object cmdlet.

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, Path

Example:

Get-Command ls | Format-List Name, CommandType, Definition, Path

Output 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 python

Output might be:

C:\Python39\python.exe
C:\Users\YourName\AppData\Local\Microsoft\WindowsApps\python.exe

This 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.

MethodCommand ExampleDescription
Get-Command(Get-Command notepad).PathReturns the full path of the executable
where.exewhere.exe notepadLists all matching executable paths
Manual PATH scanScript looping through PATH dirsCustom search for executable
Get-Command infoGet-Command lsShows if the command is alias, function or an executable

You may also like the following tutorials:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.