【发布时间】:2019-12-05 23:34:03
【问题描述】:
我了解到您可以将参数传递给 .msi 文件,但我不知道如何正确执行。我尝试了以下方法,其中$ArgumentList 是一个数组。
$ArgumentList = @("/i .\NSClient v67.msi", "/norestart", "/quiet", "/l*v '$directory'", "token=$token", "host=$_host", "mode=$mode")
Start-Process "msiexec" -ArgumentList $ArgumentList -Wait -NoNewWindow
这是我的脚本的一部分,我试图通过执行命令在我的机器上安装 NetSkope。
理论上,该命令应该类似于msiexec /i "NSClient v67.msi" token=loremipsum host=bryan.goskope.com mode=peruserconfig /norestart /quiet /l*v "C:\Temp\NetskopeInstallation.log。
#Find file path
$rawPath = Invoke-Expression -Command 'C:\Windows\System32\WHERE /r C:\Users\ /f NSClient*.msi'
#Extract the directory
$filePath = Invoke-Expression -Command "cmd.exe --% /c FOR /f ""tokens=1"" %A IN ($rawPath) DO (ECHO
'%~dpA')"
#Cast $filePath to work with string methods
$filePath = Out-String -InputObject $filePath
$filePath = $filePath.split("'")[1]
Invoke-Expression -Command "cmd.exe --% /c cd $filePath"
$ArgumentList = @("/i .\NSClient v67.msi", "/norestart", "/quiet", "/l*v '$directory'",
"token=$token", "host=$_host", "mode=$mode")
Start-Process "msiexec" -ArgumentList $ArgumentList -Wait -NoNewWindow
【问题讨论】:
-
请检查:PowerShell MSI Module 和 secondary。请检查这两个基本答案中包含的不同链接,也有指向您直接询问的链接。直接链接到 github.com:github.com/heaths/psmsi
-
我会使用 Stein 提到的 Heath 的模块。我还将重命名您的 MSI 并删除空格以避免又一个调试问题。一旦你得到它的工作,你总是可以把空间放回去。
标签: powershell arguments windows-installer