windowspowershellpowershell-2.0windows-server-2008uninstallation

Install MSI packages with Powershell 2 on Win 2008


My Powershell 2.0 😕 script is installing an MSI package using something like the following excerpt.

(...)
msiexec.exe /norestart /qn /passive `
        /l*v "$Dir\Install.log" `
        /i "$dirTemp\$msi" `
        INSTALLFOLDER="$Dir"
(...)

It runs successfully, but I would like the script to wait for the installation to end before proceeding to the next instructions. Is there a way to force the script to wait msiexec to finish?

20220909 EDIT: Tried suggested answer ⬇️

As suggested, I've tried Start-Process as shown bellow.

$Dir = "c:\test"
$dirTemp = $env:TEMP
$msi = "package.msi"
$proxy = "1.2.3.4"
$metadata = "value"

$argList = @('/norestart',
            '/qn',
            '/passive',
            '/l*v',
            "$Dir\Install.log",
            '/i',
            "$dirTemp\$msi",
            "INSTALLFOLDER='$Dir'",
            "LOGFILE='$Dir\Agent.log'",
            "SERVER='$proxy'",
            "BUFFERFILE='$Dir\Agent.db'",
            "METADATA='windows $metadata'")
Start-Process msiexec.exe -ArgumentList "$argList" -Wait -PassThru

By using Start-Process, Windows Installer fails to start and only shows me the msiexec "help" window.

enter image description here

I could not find a syntax error. Also, there's no logs to be found at the appointed log directory.

Thank you

20220910 EDIT: Found the issue ⬇️

I had to change the single quotation marks from one of the parameters to a double quotation and scape them.

"METADATA=`"windows $metadata`""

It seems msiexec did not like the space inside the parameter's value.


Solution

  • PS2 also has the cmdlet start-process if I remember correctly. There you can specify the parameter "-wait":

    $argumentList = @(
        '/norestart'
        '/qn'
        '/passive'
        '/l*v'
        "$Dir\Install.log"
        '/i' 
        "$dirTemp\$msi"
        "INSTALLFOLDER='$Dir'"
    )
    
    $result = start-process msiexec.exe -ArgumentList $argumentList -Wait -PassThru