我正在尝试运行 powershell 脚本来使用 msiexec.exe 安装应用程序。
msiexec.exe /a“C:\Users empuser\Desktop\AppInstall.msi”/被动等待
所以我希望在继续执行其余命令之前完成安装,以防止搞乱整个自动化过程。
运行脚本后,它会弹出一个 Windows 安装程序菜单,其中显示所有 msiexec 选项。我认为我在行尾错误地使用了 wait 参数。已经花了很多时间在谷歌上搜索任何解决方案...我将不胜感激任何帮助。
你可以使用
$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
以满足您的需求。我喜欢第二种方法,因为它使冗长的代码中的参数更容易阅读。
作为进程或作业运行可能对您没有什么影响,但如果确实如此,那么只需选择最适合您需求的一个即可。
Start-Process msiexec.exe -Wait -ArgumentList '/a "C:\Users\tempuser\Desktop\AppInstall.msi" /passive'
来源:https://powershellexplained.com/2016-10-21-powershell-installing-msi-files/
您还可以使用带有 /wait 开关的“start”命令
启动/等待 msiexec -passive -i package.msi