Powershell

How to Run an Exe From PowerShell

PowerShell is a command-line tool to automate various tasks such as creating, opening, or modifying files. It comes with built-in support for Microsoft Windows. Moreover, you can install it on various Linux distributions and macOS. PowerShell also supports scripting language to perform programming-related tasks. It operates four different commands: cmdlets, executable programs, PowerShell Functions, and PowerShell Scripts. You can check the list of all four types of commands by using “Get-Command” in your PowerShell. Among all these commands, cmdlets are the most used command.

PowerShell supports a variety of files to be executed using commands. Executable (.exe) files are one of them. The .exe files start operating once they are opened. These .exe files can be created via various methods such as C or C++ language and Python. The operating system does not bother how or why this file was created. It just acts to run the file. Once the .exe file is created, you do not have to perform any coding or extra tasks. You must follow the instructions.

Moreover, the .exe files can contain any content inside, but the condition is that it must be executed once it is opened. The variety of PowerShell cmdlets provide support to open the .exe files.

In this article, we will refer to numerous methods to run a .exe file with the help of Windows PowerShell:

How to Run .exe Files Using PowerShell

There are various ways to run an .exe file using the PowerShell terminal.

At first, open your PowerShell terminal. Click on the Search icon on the start menu and search for PowerShell. Once you find your search result, click on PowerShell. Open it to start writing:

Method 1

Open your PowerShell terminal. Once it is opened, trace the location of the .exe file. In my case, the .exe file is stored in directory “C:\users\adnan\downloads“, and the file’s name is “Batmon.exe“. So, you have to move your terminal to the targeted directory. You have to use the “cd” command to change the directory:

> cd downloads

As you can check, the present working directory has been changed to downloads. You can execute the following command to check the file resides in the folder or not:

> Get-ChildItem

“Batmon.exe” exists in the directory;

So, the next command which will open the file is given below:

> .\Batmon.exe

It is mandatory to write “.\” before the .exe file name. Otherwise, the command will not run. The installer of “Batmon.exe” will start operating after the successful execution of the command:

Furthermore, you can perform this method using PowerShell ISE. It is observed that PowerShell ISE provides the dropdown list of the files available in the targeted directory. In “Method 1“, the target directory is “C:\users\adnan\downloads“, so navigate your terminal to this directory. When you type “.\”, it will open a drop-down list of available files, as shown below:

Moreover, if you type the name of the .exe file, the filename will be displayed in the dropdown list, and when you can press enter to execute the .exe file:

Method 2

This method uses the Start-Process cmdlet. The stated cmdlet PowerShell with the “-FilePath” option takes the complete path of the .exe file. Moreover, “-ArgumentList” specifies the parameters when the process starts in PowerShell. Whereas “-PassThru” is used to verify that the cmdlet worked as you intended.

For instance, I want to open “filelister.exe“, which resides in the directory: C:\users\adnan\downloads\filelister.exe.

Copy the path of the .exe file and paste in the command given below:

> Start-Process -Wait -FilePath ‘C:\users\adnan\downloads\filelister.exe’ -ArgumentList/s’ -PassThru

When you enter the command, it will open the requested .exe file and operate:

Another way to execute the .exe file is by using the same cmdlet Start-Process. However, this time, we will navigate the terminal to the directory of the .exe file. For example, we want to open the “filelister.exe” that is placed in “C:\users\adnan\downloads“. Change the directory to downloads using the following command:

> cd downloads

After moving to the location, you have to execute the following command to run “filelister.exe“:

> Start-Process filelister.exe

You can also perform method 2 using PowerShell ISE. PowerShell ISE is more user-friendly because it shows the complete cmdlet list starting with the first word you type.

Open PowerShell ISE and navigate to the .exe file location. Execute the Start-Process cmdlet as given below:

> Start-Process filelister.exe

The command and the output in both cases are the same. However, one output is generated from PowerShell, and the other output is generated from PowerShell ISE

Conclusion:

PowerShell automates various tasks of the Windows operating system. It can execute a variety of files; executable files or .exe are one of them. This guide will help you learn something new about PowerShell. In this post, we have demonstrated several methods to run an .exe file from Windows PowerShell. The built-in Start-Process cmdlet of PowerShell is the most used to open .exe files.

About the author

Adnan Shabbir