我正在尝试将参数传递给MSI安装程序:

$Servers = @("ServerOne", "ServerTwo", "ServerThree")

$InstallerArguments = @(
    "/i `"$InstallerPath`"",
    "/quiet",
    "/log `"$LogFile`"",
    "EMAILSERVER=`"$Servers[0]`"",
    "DATABASESERVER=`"$Servers[1]`"",
    "SHAREPOINTSERVER=`"$Servers[2]`"",
    "USERNAME=`"$UserName`""
)

查看安装程序日志文件显示结果:
Property(S): EMAILSERVER = ServerOne ServerTwo ServerThree[0]
Property(S): DATABASESERVER = ServerOne ServerTwo ServerThree[0]

预期结果:
Property(S): EMAILSERVER = ServerOne

我想我需要以某种方式转义索引,代码有什么问题?

编辑(将参数传递给安装程序):
Start-Process -FilePath msiexec.exe -ArgumentList $InstallerArguments -Wait

最佳答案

这正是您想要的。我想你确实想要引号。

$Servers = @("ServerOne", "ServerTwo", "ServerThree")

$InstallerArguments = @(
    "/i `"$InstallerPath`"",
    "/quiet",
    "/log `"$LogFile`"",
    "EMAILSERVER=`"$($Servers[0])`"",
    "DATABASESERVER=`"$($Servers[1])`"",
    "SHAREPOINTSERVER=`"$($Servers[2])`"",
    "USERNAME=`"$UserName`""
)

关于powershell - 将安装程序参数作为数组的索引传递,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49391330/

10-13 07:51