Home > Net >  Uninstall programs with Powershell 2 on Win 2008
Uninstall programs with Powershell 2 on Win 2008

Time:09-09

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 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?

Thank you

CodePudding user response:

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

CodePudding user response:

Since Windows Installer 1.0 was first released, msiexec.exe has always run in the Windows subsystem. That means that when it is executed from the console or by a batch script control returns to the console or script immediately.

In this scenario I like to use start /wait from the command line or a batch script. This will create the process and wait for it to exit, and the return code from the process is passed through and returned from the start command such that %ERRORLEVEL% is set accordingly.

start /wait msiexec.exe followed by your remaining parameter

  • Related