PowerShell批量安装msi后辍软件的方法

2019-09-30 18:26:42王旭

如果你要安装的MSI包不止一个,可不能使用Invoke-Item,否则PowerShell不会等待前一个安装包安装完毕,就已经运行下一个安装包了。
如果在批处理中,我们可能会使用msiexec file.msi /wait。在PowerShell中也可以借助于msiexec。
先就这些安装包路径存储到数组中吧:
$msi = @("c:file1.msi", "c:file2.msi", "c:file2.msi")
然后使用Start-Process的-wait参数,等到前一个安装程序运行完毕后,再启动下一个:
foreach($_ in $msi)
{
  Start-Process -FilePath msiexec -ArgumentList /i, $_, /qn -Wait
}
另外一个办法是把输出结果重定向一些Null,也能保证程序等待安装完成:
foreach($_ in $msi)
{
   msiexec /i $_ /qn | out-null
}

文章出处:http://www.pstips.net/install-multiple-msi-using-powershell.html