2

I'm trying to write a script to install software on many computers. The problem is, they have to be installed in specific order and I need to know that the first installation succeeded before running the second one.

here's the important code:

[...]

# source_one
$Argumente = @("/i", $path_to_source, "/qb", "ADDLOCAL=ALL")
if (!$visWeb_upToDate)    { 
  Write("VIS Web-Client Installation...")
  $procWeb = Start-Process msiexec.exe -ArgumentList $Argumente -Verb runAs -PassThru 
  $procWeb.WaitForExit()
  Write-Debug($procWeb.ExitCode)

  if ($procWeb.ExitCode -eq 0){
    Write("... erfolgreich.")
    $visWeb_upToDate = $true;
  }
  else {
    Write-Error("... nicht erfolgreich.")
    Write-Error("Bitte Clients manuell installieren.")
  }
}

# source_two
if ($visWeb_upToDate -and !$vis64_upToDate){
  Write("VIS 64-Bit Client Installation...")
  $Argumente[1] = $path_to_another_source
  $procWeb64 = Start-Process msiexec.exe -ArgumentList $Argumente -Verb runAs -PassThru 
  $procWeb64.WaitForExit()
  Write-Debug($procWeb64.ExitCode)

  if ($procWeb64.ExitCode -eq 0){
    Write("... erfolgreich.")
    $vis64_upToDate = $true
  }
  else {
    Write-Error("... nicht erfolgreich.")
    Write-Error("Bitte 64-Bit Client manuell installieren.")
  }
}

[...]

I don't get $procWeb.ExitCode on Windows7 Powershell. On Win8 it works just fine and installs source_one and source_two only on success of the first.

Does somebody know how to fix this, or is there some other way to set $visWeb_upToDate = $true for both systems?

Many thanks in advance.

1 Answer 1

1

Your issue is identified as a bug in powershell.

You can get the exitcode, but only after Calling the .HasExited property of the process and using a strange syntax.

So as an example change the code to:

if ($procWeb.HasExited -and ($procWeb.GetType().GetField("exitCode", "NonPublic,Instance").GetValue($procWeb)) -eq 0){
  Write("... erfolgreich.")
  $visWeb_upToDate = $true;
}
  else {
    Write-Error("... nicht erfolgreich.")
    Write-Error("Bitte Clients manuell installieren.")
  }
}

Find the details on the bug here

Sign up to request clarification or add additional context in comments.

1 Comment

right now, I am trying your suggestion. As for now it seems to work. in a few minutes I will see if it works for every single case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.