0

I'm using Powershell on Win 2008r2 to make a remote call to msiexec as follows:

Invoke-Command -session $Session -ScriptBlock{param($arguments) start-process -FilePath "msiexec.exe" -Wait $arguments } -Argument $arguments

Currently I'm checking for success using if(!$?) but this is no good because I've just seen the msiexec process throw a 1638 error (because the app is already installed on the remote server) but the value of $? was True.

Can anyone please tell me how I can capture the 1638 code, or whatever else, is returned by msiexec on the remote server?

Thanks, Rob.

Rob Bowman
  • 7,632
  • 22
  • 93
  • 200

1 Answers1

1

This was a very hackish way to do this, but I got around this by using a global-like variable in terms of $script:functionexitcode which I would assign with the value of the .ErrorCode from the msiexec.exe using Start-Process.

Then in the main part of the PowerShell script, I would test that value if ($functionexitcode -eq 0).

Here is the full snippet from a very similar install scenario with Start-Process:

# Start MSP upgrade to UR

$upgrade = (Start-Process -Filepath $msiexecpath -ArgumentList $argumentlist_BEGIN$argumentlist_MSP$argumentlist_END -PassThru -Wait -ErrorAction Stop)

if ($upgrade.ExitCode -eq 0) {

    Write-Host "Upgrade successful. Error code:" $upgrade.ExitCode `

    "`nUpgrade logfile location: " $workingdirectory\$msi_logfile_upgrade

    $script:FunctionExitCode = $upgrade.ExitCode