如果你要安装的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
【PowerShell批量安装msi后辍软件的方法】相关文章:
★ Windows Powershell方法(对象能做什么)
★ PowerShell中执行Javascript的方法示例
★ PowerShell中使用正则和ValidateSet验证参数合法性
★ PowerShell脚本中控制Windows DNS服务的方法
★ PowerShell: Try...Catch...Finally 实现方法