We have all downloaded and installed software on our Windows platform at some point. As you may know, the file that you download from the web or a drive comes with a .exe extension which shows that it is an executable file. When you run this file, it executes a set of encoded instructions that the system will execute to install software on your system, so you can start using it.
An executable file can have hundreds of different file extensions, and “.exe” is just one of them. From a usability standpoint, the easiest way to run a .exe file is to double-click on it and follow the instructions it prompts. These files can also be executed through third-party software.
But did you know that you can run .exe files through PowerShell? You’ll be surprised how easy it is to do.
In this article, I will show you three different ways to run .exe files through PowerShell.
Navigate to the File Directly
If you know the exact location of your executable file, simply navigate to it through your PowerShell editor or the regular command prompt. However, some computers may require admin rights to run .exe files, so you may want to switch to an admin account in that case.
Once you have the admin rights, go to the folder or directory that contains the .exe file.
For example, let’s say you have a file called “myprogram.exe” located in C:/Users/admin/testfolder/experiments.
To run this .exe file, open PowerShell and use the “cd” command:
c:\Users\admin> cd testfolder
c:\Users\admin\ testfolder> cd experiments
Now, you’re in the experiments folder.
Next, run myprogram.exe like this:
C:\Users\admin\ testfolder\experiments> .\myprogram.exe
Note that you have to use “.\” to run .exe files in PowerShell. Otherwise, the .exe file will not be executed, though you will get no errors either. The statement will simply be passed on by PowerShell.
When you run this command, the .exe file will execute, and it could open a wizard or a license agreement as per the contents of the .exe file. Depending on the program and the way it is programmed, you may want to pass parameters to it.
To send parameters to the .exe file:
C:\Users\admin\ testfolder\experiments> .\myprogram.exe 12
Here, “12” is the input that you’re sending to the .exe file for processing.
The Exact Filename is not Known
Sometimes, you may not know the exact name of the file. This is why some PowerShell editors will display all the files in a folder when you type “.\” Many times, it will display all the files in a folder in the form of a drop-down menu and you can choose a file from it.
Another option is to use the “Get-ChildItem” cmdlet. This can be particularly useful in older PowerShell editors. Simply navigate to the folder and type “Get-ChildItem. This will display the names of all the files, the last write time, access mode, and other details. You can look through this list and type the name of the .exe file you want to execute.
C:\Users\admin\ testfolder\experiments> Get-ChildItem
In the above option, you navigated to the folder to run the .exe file. But how can you do it through a script?
Using the Invoke-Expression cmdlet.
This command is used for running commands and expressions on the local device. Its syntax is:
You can run the “myprogram.exe” file mentioned in the above example like this:
Invoke-Expression -Command “C:\Users\admin\ testfolder\experiments\myprogram.exe”
Another way to express the above command is:
“C:\Users\admin\ testfolder\experiments\myprogram.exe” | Invoke-Expression
Both the commands have the same result and are just different forms of expression.
Note that some executable files may require parameters, in which case, use the $Input variable of the “command” parameter to pipe values to Invoke-Expression. Likewise, you can use its Output via the “command” parameter.
Thus, this is how you can use the Invoke-Expression cmdlet to run .exe files in PowerShell.
The next method to run .exe files in PowerShell is by using the Start-Process cmdlet.
This cmdlet starts one or more processes on your local device.
This is how the Start-Process cmdlet looks:
You only need the -FilePath parameter to run .exe files in PowerShell. In our above example, simply navigate to the “testfolder/experiments” folder and type:
Start-Process -FilePath “myprogram.exe”
This will run the executable file. If you are in a different directory, use the “-WorkingDirectory” parameter to instruct PowerShell to navigate to “testfolder/experiments” and run the “myprogram.exe” file in it.
The code will look like this:
Start-Process -FilePath “myprogram.exe” -WorkingDirectory “C:\Users\admin\testfolder\experiments”
Thus, this is how you can use the Start-Process cmdlet to run .exe files in PowerShell.
You can choose from the above three methods and the results won’t change at all. The choice depends more on your preferences and where you are executing the file. For example, if you want to run .exe files as a part of a code for a larger program, use the Start-Process or Invoke-Expression cmdlet as this can be embedded as a code.
On the other hand, if you want to run .exe files from a PowerShell editor or the command line, choose the first option.
To conclude, PowerShell automates many tasks that you do manually on the Windows platform, and one such task is running executable files.
You can run .exe files in PowerShell using three different methods:
- Typing “.\” followed by the name of the file
- Using Invoke-Expression
- Using Start-Process cmdlet
Though the final result will not change, you can choose the method according to your technical skills and coding requirements.
We hope this helps you to run .exe files in PowerShell with ease. Make sure to read through our tutorials on PowerShell.
2 thoughts on “Three ways to run .exe files in PowerShell”
If these methods STILL fail, is there anything that can be concluded regarding the nature of the .exe file?
Guten Tag Lavanya,
there is a difference when running a program from command line with “Invoke-Expression” or “Start-Process” in form of how (or where) the program is being executed.
I just tried it with the VMware created ovftool.exe.
Using “Start-Process ovftool.exe –help” it will fire up the command in a separate window that will immediately disappear whereas using the command “Invoke-Expression .\’ovftool.exe –help'” it will execute the command in the window from where I called the command. This is perhaps good to know.