How to install .MSI using PowerShell

173,505

Solution 1

When trying to silently install an MSI via PowerShell using this command:

Start-Process $webDeployInstallerFilePath -ArgumentList '/quiet' -Wait

I was getting the error:

The specified executable is not a valid application for this OS platform.

I instead switched to using msiexec.exe to execute the MSI with this command, and it worked as expected:

$arguments = "/i `"$webDeployInstallerFilePath`" /quiet"
Start-Process msiexec.exe -ArgumentList $arguments -Wait

Hopefully others find this useful.

Solution 2

Why get so fancy about it? Just invoke the .msi file:

& <path>\filename.msi

or

Start-Process <path>\filename.msi

Edit: Full list of Start-Process parameters

https://ss64.com/ps/start-process.html

Solution 3

You can use:

msiexec /i "c:\package.msi"

You can also add some more optional parameters. There are common msi parameters and parameters which are specific for your installer. For common parameters just call msiexec

Solution 4

#Variables
$computername = Get-Content 'M:\Applications\Powershell\comp list\Test.txt'
$sourcefile = "\\server\Apps\LanSchool 7.7\Windows\Student.msi"
#This section will install the software 
foreach ($computer in $computername) 
{
    $destinationFolder = "\\$computer\C$\download\LanSchool"
    #This section will copy the $sourcefile to the $destinationfolder. If the Folder does not exist it will create it.
    if (!(Test-Path -path $destinationFolder))
    {
        New-Item $destinationFolder -Type Directory
    }
    Copy-Item -Path $sourcefile -Destination $destinationFolder
    Invoke-Command -ComputerName $computer -ScriptBlock { & cmd /c "msiexec.exe /i c:\download\LanSchool\Student.msi" /qn ADVANCED_OPTIONS=1 CHANNEL=100}
}

I've searched all over for this myself and came up with zilch but have finally cobbled this working script together. It's working great! Thought I'd post here hopefully someone else can benefit. It pulls in a list of computers, copies the files down to the local machines and runs it. :) party on!

Solution 5

After some trial and tribulation, I was able to find all .msi files in a given directory and install them.

foreach($_msiFiles in 
($_msiFiles = Get-ChildItem $_Source -Recurse | Where{$_.Extension -eq ".msi"} |
 Where-Object {!($_.psiscontainter)} | Select-Object -ExpandProperty FullName)) 
{
    msiexec /i $_msiFiles /passive
}
Share:
173,505

Related videos on Youtube

New Developer
Author by

New Developer

C# application developer

Updated on July 09, 2022

Comments

  • New Developer
    New Developer almost 2 years

    I am very new to PowerShell and have some difficulty with understanding.
    I want to install an .MSI inside PowerShell script.
    Can please explain me how to do that or provide me beginners level tutorial.

    $wiObject = New-Object -ComObject WindowsInstaller.Installer
    ?????
    
  • ohlmar
    ohlmar almost 10 years
    You have to give some comments to your answer
  • Brettski
    Brettski almost 8 years
    And you can simply add switches and other parameters to this?
  • maxc137
    maxc137 about 3 years
    Also you can do -ArgumentList '/quiet /passive. /passive removes any UI that will be shown with just /quiet
  • Trisped
    Trisped almost 2 years
    Please add a description of the code. What it does, how it does it, how to use it, etc.