MSIExec通过Powershell安装

问题描述 投票:1回答:1

从目录中查找MSI文件列表,并在远程或本地安装在给定的PC上。我希望能够运行一个脚本,它将在给定的目录1中安装8个单独的MSI文件1.我发现这个脚本并认为它有效,但我觉得它好像缺少一些正确的东西?

foreach($_msiFiles in 
($_msiFiles = Get-ChildItem $_Source -Recurse | Where{$_.Extension -eq ".msi"} |
 Where-Object {!($_.psiscontainter)} | Select-Object -ExpandProperty FullName)) 
{
    msiexec /i $_msiFiles /passive
} 
powershell windows-installer msiexec
1个回答
1
投票

它可以帮助您了解这里发生了什么。我会写这样的东西:

声明源目录:

$source = “\\path\to\source\folder”

将每个子.msi对象放入一个数组中:

$msiFiles = Get-Childitem $source -File -recurse | Where-Object {$_.Extension -eq “.msi”}

迭代数组来运行每个.msi:

Foreach ($msi in $msiFiles) {

Msiexec /I “$($msi.FullName)” /passive

}

这当然只是对你正在做的事情的解释。它不包括任何错误处理,检查返回代码或远程命令语法等。

© www.soinside.com 2019 - 2024. All rights reserved.