本文介绍了如何使用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文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 16:00