How to Run Executable Files in PowerShell
- Running Executable Files in PowerShell
-
Running Executable Files Using the
Start-Process
Cmdlet in PowerShell - Running Executable Files Silently in PowerShell
PowerShell automates many Windows operating system tasks. For example, it can execute various files like executable files or .exe
.
This article will demonstrate several methods to run an executable file from Windows PowerShell.
Running Executable Files in PowerShell
Open your PowerShell terminal. Trace the location of the .exe file and make it your working directory.
Then, use the cd
command to change the directory. Once you have adjusted your working directory, you may run your executable file by calling it to the command line.
.\setup.exe
However, this method will not suffice if we want to pass arguments. We have a legacy command called msiexec
in the command prompt.
The following section will discuss the proper counterpart to msiexec
in PowerShell.
Running Executable Files Using the Start-Process
Cmdlet in PowerShell
The Start-Process
cmdlet can run executable files in PowerShell. The stated PowerShell cmdlet and -FilePath
parameter takes the complete path of the .exe
file.
Moreover, the -ArgumentList
parameter specifies the internal parameters used by the executable file when the process starts in PowerShell.
Finally, the -PassThru
parameter is used to verify that the cmdlet worked as you intended. For example, I want to open an executable file named setup.exe
.
Start-Process -Wait -FilePath '.\setup.exe' -ArgumentList '/s' -PassThru
Once executed, PowerShell will run the defined executable file.
Running Executable Files Silently in PowerShell
Running executable files in Windows PowerShell takes advantage of the msiexec
legacy command that we usually use to run executable files in the command prompt.
To run the executable files silently, we must use specific msiexec
parameters and pass them to the -ArgumentList
parameter.
Here is the list of parameters that we need to run an executable file silently in PowerShell.
- The
/s
runs the installation in silent mode. - The
/v
pass command-line options and values of public properties through toMsiexec.exe
. - The
/q
sets the user interface level. - The
n
is the interface level of the/q
parameter. This switch will run the installation with no UI.
If we combine all of these parameters, this is how the PowerShell script should look. For more info on msiexec
arguments, you may run the msiexec
command in PowerShell.
Start-Process -Wait -FilePath '.\setup.exe' -ArgumentList '/s /v/qn' -PassThru
The installation should run in silent mode with no UI prompts by executing the snippet above.
Note that /v
and /qn
are executed with no spaces because the /qn
parameter is executed as a function of the /v
parameter.
Marion specializes in anything Microsoft-related and always tries to work and apply code in an IT infrastructure.
LinkedIn