如何使用 PowerShell 将参数传递给 MSI 文件 [英] How to pass arguments to MSI file with PowerShell

查看:25
本文介绍了如何使用 PowerShell 将参数传递给 MSI 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到您可以将参数传递给 .msi 文件,但我不知道如何正确执行.我尝试了以下方法,其中 $ArgumentList 是一个数组.

I've read that you can pass arguments to a .msi file, but I have no idea how to do it correctly. I've tried the following, where $ArgumentList is an array.

$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.

This is part of my script, where I'm trying to install NetSkope on my machine by executing a command. In theory, the command should look like 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

推荐答案

这里的语法略有不同:

$MSIArguments = @(
    "/x"
    "`"C:\path with spaces\test.msi`""
    "/qb"
    "/norestart"
    "/l*v"
    "`"C:\path with spaces\test.log`""
)

Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow 

这篇关于如何使用 PowerShell 将参数传递给 MSI 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆