.EXE files, or “executable files” are something we see often. Most downloaded files, especially setups, are executable files that are ready to be run and installed on your system. At other times, files may still be executable but have a different file extension, like “.msi”, “.bat”, or “.inf”.
Even though you can run such files by double-clicking them using File Explorer, the method may not be ideal for every situation. You can also run executable (.exe) files directly from Windows PowerShell. Some people may prefer the command-line method as you can run an executable without having to navigate here and there.
In this article, we show you 4 methods to run .exe files directly inside PowerShell. The commands discussed in the methods below can also be applied to PowerShell scripts. Moreover, some of them even allow you to send parameters/values to the executable file.
Table of Contents
How to Run EXE Files in PowerShell
In all of the methods discussed below, you must know the complete directory path to the file that you want to run in PowerShell. While one of the methods requires you to navigate to the .exe file directory and then execute the file, the other methods need complete file paths in the command.
In the example below, we will be running “Rufus.exe” located at “C:\Users\Subhan\Downloads.” Of course, this will change for you according to the file’s path and its name.
Run EXE File Directly from PowerShell
When we say “directly,” we mean that this method to run an executable file does not need any special PowerShell commands. All it needs is a path and the name of the file to run.
Launch an elevated PowerShell instance.
Use the “CD” command to change the directory to the executable file’s location:
CD "[PathToExecutableFile]"
Alternatively, you can also jump one folder at a time using the following pattern:
# Change directory to the root of the current volume CD\ # Change direcoty to root of the C drive CD C: CD Users CD Subhan CD Downloads
Now that you’re inside the directory of the file, use “.\” followed by the complete name of the executable file.
Note: Apart from the [FileName], you can also change the file type/extension depending on the actual file type.
.\[FileName].exe
The executable file will now run.
You can also run the executable file whilst sending a parameter to the file, as in the example below:
.\Rufus.exe 10
In this example, the parameter “10” will be sent to Rufus.exe.
Note that it is crucial that you use “.\” while running an executable file directly. Otherwise, it will be considered a PowerShell command and you may see an error.
Additionally, if you find yourself lost while navigating/changing the directories, or are unsure of the file name, you can use the following cmdlet to get a list of the items inside the current directory:
Get-ChildItem
Run EXE File in PowerShell Using Invoke-Expression Command
Another way to run an executable file using PowerShell is by using the “Invoke-Expression
” cmdlet. You can use this cmdlet directly in PowerShell, or insert the full command inside a PowerShell script (.ps1) to run an executable. This way, you can open a document file directly inside the app/program you are writing the script for.
To run an executable file in PowerShell or PowerShell script, use the following command syntax:
Invoke-Expression -Command “[PathToExecutableFile].exe”
Alternatively, the following syntax also works just as well:
“[PathToExecutableFile].exe” | Invoke-Expression
Run EXE File in PowerShell Using Start-Process Command
Like the Invoke-Expression
cmdlet, you can also use the “Start-Process
” command to run an executable file or a PowerShell script. Here’s how:
Launch an elevated PowerShell instance.
Use the following cmdlet to run an executable file:
Start-Process -FilePath ‘[PathToExecutableFile].exe’
That’s it! The executable file should now run.
Alternatively, you can also change your strategy to a directory-first approach and use a different syntax of the “Start-Process
” command to run an executable file. For that, you must first use the “CD
” cmdlet to change your directory to the location where the executable file is located, then use the following command to run it:
Start-Process [ExecutableFileName].exe
Here is an example:
Run EXE File in PowerShell Using “&” Call Operator
A Call Operator in Windows PowerShell allows you to run a command, function, or script. Anything followed by the “&” call operator is considered a command by PowerShell. You can use this logic of PowerShell to run an executable file simply by entering the file’s path prefixed with the call operator.
This is the syntax to be used to run an executable file in PowerShell:
& "[PathToExecutableFile].exe"
It is that simple.
Closing Thoughts
The easiest way to run an executable file, may it be a .exe, .ps1, or .msi file, is perhaps using the “&” call operator followed by the complete file path and extension. However, there are other ways to get the job done as well:
- Run the executable in PowerShell directly by using “.\” followed by the file name.
- Run the executable in PowerShell using the
Invoke-Expression
command. - Run the executable in PowerShell using the
Start-Process
command.
All of the 4 aforementioned methods will execute the file directly from PowerShell. This way, you do not have to browse through File Explorer to run a file each time you need to.