To run an executable from PowerShell, you can type its full path or use .ilename.exe if it’s in the current directory, then press Enter. For files in the current folder, you must prefix with .\); for system commands like notepad, just type the name. This guide covers all the methods, arguments, and common pitfalls.
Why PowerShell Runs Executables Differently
PowerShell is a command-line shell and scripting language built on .NET. Unlike CMD, it treats commands as objects, but running an executable still goes through the same Windows process creation. The key difference is that PowerShell does not search the current directory by default for security reasons. In CMD, typing program.exe works even if the file is in the current folder, but PowerShell requires an explicit path. This prevents accidental execution of malicious files placed in your working directory.
Another difference: PowerShell can run native executables, PowerShell cmdlets, functions, aliases, and scripts. When you type a name, it resolves in this order: alias, function, cmdlet, then external executable. So if you have a function named ping, it will override the system ping.exe.
Basic Ways to Run an Executable
Here are the most common methods, from simplest to more advanced:
- Full path with quotes:
& "C:\Program Files\MyApp\app.exe"– the ampersand is the call operator, needed when the path contains spaces. - Relative path:
.\app.exe– runs app.exe from the current directory. The backslash is required. - Just the name (if in PATH):
notepad– works for system executables or any folder listed in the PATH environment variable. - Start-Process (async):
Start-Process notepad– launches the program without waiting for it to finish, useful for GUI apps. - Invoke-Expression (avoid):
iex "app.exe"– evaluates a string as a command; risky if the string contains user input.
Passing Arguments and Capturing Output
To pass arguments, just add them after the command, separated by spaces. If an argument contains spaces, enclose it in quotes. For example:
& "C:\Tools\backup.exe" -source "C:\My Documents" -dest "D:\Backup"
PowerShell passes the arguments as a single string to the executable, so quoting rules are similar to CMD. To capture output, assign the result to a variable:
$output = & "C:\Tools\script.exe" --version
Write-Host $output
For executables that write to stderr, you can redirect with 2>&1. To capture both streams separately, use Start-Process with -RedirectStandardOutput and -RedirectStandardError.
Common Problems and How to Fix Them
Here are the typical errors users encounter:
- “The term ‘foo’ is not recognized…” – The executable is not in the current directory and not in PATH. Use
.\foo.exeor full path. - “Access is denied” – The file may be blocked (downloaded from the internet). Unblock with
Unblock-File foo.exeor by right-clicking → Properties → Unblock. - “This program cannot be run in DOS mode” – The file is not a valid Windows executable, or it’s a 16-bit program not supported on 64-bit Windows.
- Missing DLL errors – The executable depends on libraries not installed. Reinstall the program or install the required Visual C++ Redistributable.
- PowerShell blocks scripts but not .exe – Execution policy only affects scripts (.ps1), not executables. If you see this, you’re trying to run a script, not an exe.
Running as Administrator or Different User
To run an executable with elevated privileges, use Start-Process -Verb RunAs:
Start-Process "C:\Tools\setup.exe" -Verb RunAs
This triggers the UAC prompt. To run as a different user, use Start-Process -Credential (Get-Credential). For scheduled tasks, use Register-ScheduledTask with the appropriate principal.
PowerShell vs CMD vs Run Dialog
CMD is simpler for quick commands but lacks object handling. The Run dialog (Win+R) also searches PATH and current directory, but you can’t pass complex arguments easily. PowerShell gives you control over output, error handling, and scripting. For example, you can check the exit code with $LASTEXITCODE after running an executable:
& "C:\Tools\check.exe"
if ($LASTEXITCODE -eq 0) { "Success" } else { "Failed" }
This is invaluable in automation scripts.
Working Directory and Environment Variables
When you run an executable, it inherits the current working directory. Some programs expect to be run from their own directory to find config files. Use Set-Location before running, or use Start-Process -WorkingDirectory:
Start-Process "C:\App\app.exe" -WorkingDirectory "C:\App"
You can also set environment variables for the process:
$env:MY_VAR = "value"
& "C:\App\app.exe"
This only affects the current PowerShell session, not the system.
Frequently Asked Questions
Why does PowerShell say “not recognized” when I type the exe name?
Because the current directory is not in the PATH. Use .\filename.exe or the full path. This is a security feature to prevent accidental execution of files in your folder.
Can I run a .exe from PowerShell without waiting for it to finish?
Yes, use Start-Process without the -Wait parameter. For example: Start-Process notepad. You can also use -PassThru to get the process object.
How do I run an executable with administrator rights from PowerShell?
Use Start-Process -Verb RunAs. This will pop up the UAC prompt. If you need to automate it without prompting, you’d need a scheduled task with highest privileges.
What does the ampersand (&) do in PowerShell?
The call operator & tells PowerShell to treat the following string as a command to execute. It’s required when the command path has spaces or is stored in a variable.
Why does my .exe run but nothing happens?
The executable might be a GUI app that returns immediately, or it might be waiting for input. Check the process with Get-Process. Also, some console apps need the terminal to stay open; use cmd /c pause or run it in a new window.
Can I run a .exe from PowerShell on Linux or macOS?
PowerShell Core runs on those systems, but you can only run native executables for that OS (e.g., ELF binaries on Linux). Windows .exe files won’t run unless you use Wine or a virtual machine.
Related
Formula used
in t | Time (min) | min | 30 | 0 in d | Distance (km) | km | 5 | 0 | 100000 out pace | Average pace (min/km) | min/km | t / d | 2 out speed | Average speed (km/h) | km/h | d / (t / 60) | 2
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Campus Tech Innovation Hubs: What They Are
- Poco C51 Airtel Prepaid Locked Variant India?
- Jenkins vs GitHub Actions: Which CI/CD Fits Your Team?
- Turn Off Backup Encryption in iTunes?
- Shared VPS Hosting: Is It Better?
- Disk Defrag Pro: What It Does and Whether You Need It