How to install MSI file using batch file in PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

Let say we have one MSI file and we need to install the MSI file on the remote computers using PowerShell but that MSI file should be deployed with the Batch file and should be executed using PowerShell.

In this example, we have a 7-zip MSI file and batch file we will first write the installation instructions as shown below.

msiexec /i "C:\temp\7z1900-x64.msi" /quiet

We have the installation MSI package located at the C:\temp location. We will save the above instruction inside the 7ZipInstaller.bat file.

Now we need to call the batch file as shown below. −Wait will wait for the batch file to execute first and then moves to the next instruction if any and −NoNewWindow will

Start-Process C:\Temp\7zipInstaller.bat -Wait -NoNewWindow

Once you run the above command, it will install 7zip at the location specified. You can directly pass these instructions inside the Start-Process to execute MSI but if we need to execute the batch file then this is a good way because we can call this batch file remotely as well. The below command is for the remote computer.

Invoke-Command -ComputerName TestMachine1, TestMachine2 -ScriptBlock{
   Start-Process C:\Temp\7zipInstaller.bat -Wait -NoNewWindow

This command will run on the computers Testmachine1 and Testmachine2. Make sure you copy the MSI package to the remote location before running this command.

Updated on 17-May-2021 12:17:21