coding
coding

Reputation: 171

Make msiexec wait until the installation completes

I am trying to run a powershell script to install an application using msiexec.exe.

msiexec.exe /a "C:\Users\tempuser\Desktop\AppInstall.msi" /passive wait

So I want the installation to be completed before moving on the rest of the commands in order to prevent messing up the whole automation process.

Once i run my script, it pops out a windows installer menu that shows all the msiexec options. I think I used the wait parameter incorrectly at the end of the line. Already spent so much googling for any solutions... I'd appreciate any helps.

Upvotes: 8

Views: 18731

Answers (3)

janv8000
janv8000

Reputation: 1625

Start-Process msiexec.exe -Wait -ArgumentList '/a "C:\Users\tempuser\Desktop\AppInstall.msi" /passive'

Source: https://powershellexplained.com/2016-10-21-powershell-installing-msi-files/

Upvotes: 2

Herb F
Herb F

Reputation: 305

You can also use the 'start' command with the /wait switch

start /wait msiexec -passive -i package.msi

Upvotes: 0

Flash_Steel
Flash_Steel

Reputation: 628

You can use

$myJob = Start-Job {[your msiexec call]}
Wait-Job $myJob 

Or

$params = @{
        "FilePath" = "$Env:SystemRoot\system32\msiexec.exe"
        "ArgumentList" = @(
        "/x"
        "$($productCodeGUID)"
        "/qn"
        "REMOVE=ALL"
        "/norestart"
        )
        "Verb" = "runas"
        "PassThru" = $true
    }

    $uninstaller = start-process @params
    $uninstaller.WaitForExit()

Tweak the params to match your needs. I like the second approach as it makes the arguments easier to read in lengthy code.

Running as a process or job may make no difference to you, but if they do then just pick the one best suited to your needs.

Upvotes: 3

Related Questions