To run an executable (.exe) file from PowerShell, you can simply type its full path or name if it’s in the current directory, followed by any arguments, and press Enter. For example, typing .\program.exe or C:\Tools\program.exe will launch that program. This guide explains the different ways to run executables in PowerShell, common pitfalls, and how to handle scripts and administrative rights.
Why PowerShell and Not CMD?
PowerShell is Microsoft’s modern command-line shell and scripting language, built on the .NET framework. It’s more powerful than the legacy Command Prompt (CMD) because it can manipulate objects (like files and folders) directly, not just text. When you run an .exe from PowerShell, you’re using the same underlying Windows process launcher as CMD, but PowerShell gives you more control over the output and error handling. For instance, you can capture the output of an .exe into a variable, use it in a script, or pipe it to other PowerShell commands.
Basic Ways to Run an .exe
There are several ways to launch an executable from PowerShell, each with its own use case.
- Direct path: Type the full path in quotes:
& "C:\Program Files\MyApp\app.exe". The ampersand (&) is the call operator, needed when the path contains spaces. - Relative path: If the .exe is in the current directory, use
.\app.exe. The dot-slash tells PowerShell to look in the current folder, which is safer than just typing the name. - Just the name: If the .exe is in a folder listed in the system’s PATH environment variable, you can type just the name, e.g.,
notepad.exe. This works for common tools likeipconfigorping. - Start-Process cmdlet: For more control, use
Start-Process -FilePath "C:\path\app.exe" -ArgumentList "-arg1". This lets you wait for the process to finish, run as a different user, or set window style.
Passing Arguments and Capturing Output
Often you need to pass command-line arguments to the executable. In PowerShell, you can just add them after the path, like .\app.exe -verbose -o output.txt. However, be careful with quoting. If an argument contains spaces, wrap it in quotes: .\app.exe "C:\My Files\data.txt". To capture the output (stdout) of an .exe into a variable, use $output = .\app.exe. The variable will contain an array of strings (one per line). To capture errors, you can redirect stderr using 2>&1 or use $LASTEXITCODE to check the exit code after the command finishes.
Common Problems and How to Fix Them
Users often run into issues when trying to execute an .exe from PowerShell. Here are the most frequent ones:
- “The term ‘app.exe’ is not recognized…” This means PowerShell can’t find the file. Either the path is wrong, or the file isn’t in the current directory or PATH. Use
Test-Pathto verify the path exists. - Execution Policy blocks scripts: If you’re trying to run a .ps1 script (not an .exe), PowerShell’s execution policy might prevent it. To run a script, you can use
powershell -ExecutionPolicy Bypass -File script.ps1or change the policy for the current user withSet-ExecutionPolicy -Scope CurrentUser RemoteSigned. This does not affect .exe files. - File is blocked by Windows: If you downloaded an .exe from the internet, Windows may mark it as blocked. Right-click the file, select Properties, and check “Unblock” if present.
- Permissions: If the .exe requires administrator privileges, you’ll get an “Access Denied” error. Run PowerShell as Administrator (right-click, “Run as administrator”) or use
Start-Process -Verb RunAsto trigger a UAC prompt.
Running Scripts vs. Executables
It’s important to distinguish between running an .exe and running a PowerShell script (.ps1). An .exe is a compiled program; a .ps1 is a text file with PowerShell commands. To run a script, you typically use .\script.ps1 or & "C:\path\script.ps1". Scripts are subject to execution policy, while .exe files are not. If you have a script that you want to run as if it were an executable, you can create a shortcut or a batch file that calls PowerShell with the script, but that’s beyond the basic scope.
Working with Administrative Rights
Some executables (like installers or system tools) require administrator privileges. If you’re in a standard PowerShell window, you’ll get an error. To run an .exe as administrator, you have a few options:
- Right-click on PowerShell and select “Run as administrator”, then execute your command.
- Use
Start-Process -FilePath "C:\path\app.exe" -Verb RunAs. This will pop up a UAC prompt; if the user agrees, the process runs elevated. - If you’re writing a script that needs to elevate itself, you can check if the current session is elevated and re-launch with
Start-Process powershell -Verb RunAs.
Be cautious: running unknown executables with admin rights can be dangerous. Only do this if you trust the source.
Frequently Asked Questions
How do I run an .exe from PowerShell with spaces in the path?
Use the call operator & and quote the path: & "C:\Program Files\My App\tool.exe". Without the ampersand, PowerShell treats the quoted string as a single string to output, not a command to execute.
Why does PowerShell say “not recognized” when I type the .exe name?
PowerShell only looks in the current directory and in folders listed in the PATH environment variable. If the file is in a different folder, you must provide the full path or change to that directory using Set-Location (or cd).
Can I run a .exe from PowerShell without opening a new window?
Yes. By default, console applications run in the same window. For GUI applications, PowerShell will not wait for them to finish unless you use Start-Process -Wait. If you want to run a console app in the background, you can use Start-Process -NoNewWindow or just run it normally.
How do I get the exit code of an .exe in PowerShell?
After running the executable, check the automatic variable $LASTEXITCODE. It contains the exit code (0 usually means success). For example: .\app.exe; Write-Host "Exit code: $LASTEXITCODE".
Is it safe to run an .exe from PowerShell?
Running any executable carries risk, regardless of the shell. Only run .exe files from trusted sources. PowerShell itself doesn’t add extra security, but it also doesn’t bypass Windows security checks. Always verify the file’s digital signature if you’re unsure.
Related
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
- Reliable Subaru vs New Honda Civic Cost
- Pokemon Bookmark Corner Designs & Pokemon GO DIY
- Forgotten Games That Created Your Favorite Genres
- Lexus vs Genesis Luxurious Compact SUV0.075 hp/lb
- Uber VW Robotaxi LA Launch Date
- Notebook vs Tablet: Which Saves You More Money?