I am trying to run msiexec.exe with powershell on remote machine using Invoke-Command but it is not passing arguments into installer. I tried in several ways, my code looks like this:
$params = @(
$DataPath = 'C:\Program Files (x86)\path'
$Type = "Dev"
$DbUser="User"
$DbPassword="password"
$sqlServerUser= "user"
$sqlServerPassword="password"
$QMName="name"
$QMAddress="address"
$QMPort="1212"
$MqUser="user"
$MqPassword="password"
$SERVER_TYPE="Dev"
$RUNTIME_SQL_AUTH_TYPE="WINDOWS_AUTH"
$SQL_AUTH_TYPE="WINDOWS_AUTH"
$RECYCLING_TIME="03:00"
)
$InstallerPath = "$Path.msi"
$scriptInstallServer =
{
(Start-Process -FilePath "msiexec.exe" -ArgumentList "/i $Using:InstallerPath /qn /norestart $Using:params" -Wait -Passthru).WaitForExit()
}
Invoke-Command -ComputerName $server -Credential $cred -ScriptBlock $scriptInstallServer
AND
Invoke-Command -ComputerName $server -Credential $cred -ScriptBlock {msiexec /i $Using:serverInstallerPath $Using:params /passive}
I have tried: Install MSI on remote host using powershell
Your attempt to create an array won't work as intended:
This is the same as
$params = @(), i.e. creating an empty array, and creating individual variables named$DataPath,$Type, ...; that is, your use of@(...), the array-subexpression operator encloses variable assignments, which themselves output nothing, so that the resulting array is empty.If the intent is to define
$paramsas an array of CLI arguments formsiexec, specifically asPROPNAME=PROPVALUEarguments, you need to use this instead:Note the use of literal property names, the need to quote each argument (line) as whole, the absence of whitespace around
=, and the embedded, selective"..."quoting for property values that contain spaces.Then you should be able to call as follows: