让 msiexec 等待安装完成

cod*_*ing 6 powershell windows-installer

我正在尝试运行 powershell 脚本来使用 msiexec.exe 安装应用程序。

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

因此,我希望在继续执行其余命令之前完成安装,以防止弄乱整个自动化过程。

运行脚本后,它会弹出一个 Windows 安装程序菜单,其中显示所有 msiexec 选项。我认为我在行尾错误地使用了 wait 参数。已经花了很多时间在谷歌上搜索任何解决方案......我将不胜感激任何帮助。

Fla*_*eel 3

您可以使用

$myJob = Start-Job {[your msiexec call]}
Wait-Job $myJob 
Run Code Online (Sandbox Code Playgroud)

或者

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

    $uninstaller = start-process @params
    $uninstaller.WaitForExit()
Run Code Online (Sandbox Code Playgroud)

调整params以满足您的需求。我喜欢第二种方法,因为它使冗长的代码中的参数更容易阅读。

作为进程或作业运行可能对您没有影响,但如果有的话,只需选择最适合您需求的一个即可。