我正在尝试运行以下命令并打开windows安装程序参数,我做错了什么?
$current_pc = "$env:computername"
$filePath = "c:\users\ArA\Desktop\parameters.csv"
$machineParams = Import-CSV $filePath
$info = if($machineParams){$machineParams | where {$_.branch -eq $($current_pc.Substring($current_pc.length - 3,3))}}
else{write-output "CSV not loaded"}
$info
start-process msiexec.exe -Wait -ArgumentList /L* "c:\users\Ara\Desktop\t.log" /qn /I "c:\users\Ar\Desktop\setup.msi" DATABASE_ID=$($info.DATABASE_ID),ODBC_DATABASE_NAME=$($info.ODBC_DATABASE_NAME),ODBC_ENGINE_NAME=$($info.ODBC_ENGINE_NAME) ODBC_HOST_NAME=$($info.ODBC_HOST_NAME) NOLAN=1
答案 0 :(得分:1)
你可能是如何传递你的论点的。作为最佳实践,我在传递exe
参数时使用数组,以便正确解释它们:
$machineParams = Import-Csv -Path $Env:UserProfile\Desktop\parameters.csv
$info = if ($machineParams) {
$machineParams |
Where-Object { $_.branch -eq $Env:ComputerName.Substring($Env:ComputerName.Length - 3, 3) }
} else {
'CSV not loaded.'
}
$info
$StartArgs = @{
'Wait' = $true
'FilePath' = "$Env:SystemRoot\System32\msiexec.exe"
'ArgumentList' = @(
'/i',"$Env:UserProfile\Desktop\setup.msi"
'/qn'
'/log',"$Env:UserProfile\Desktop\t.log"
)
}
if ($info -ne 'CSV not loaded.') {
$StartArgs['ArgumentList'] += @(
"DATABASE_ID=$($info.DATABASE_ID)"
"ODBC_DATABASE_NAME=$($info.ODBC_DATABASE_NAME)"
"ODBC_ENGINE_NAME=$($info.ODBC_ENGINE_NAME)"
"ODBC_HOST_NAME=$($info.ODBC_HOST_NAME)"
'NOLAN=1'
)
}
Start-Process @StartArgs