gpt4 book ai didi

powershell - 使 msiexec 等待安装完成

转载 作者:行者123 更新时间:2023-12-02 22:46:35 30 4
gpt4 key购买 nike

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

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



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

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

最佳答案

您可以使用

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

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

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

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

作为一个流程或工作运行可能对您没有任何影响,但如果他们这样做了,那么只需选择最适合您需求的一个。

关于powershell - 使 msiexec 等待安装完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38481952/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com