Hello,
My company is currently in the process of transitioning from SCCM 2007 to 2012 and we are having some difficulties getting application deployment to work correctly. We have recently found that there appears to be an disconnect between the powershell script that we use to install the software and the process that is started. Whenever we start the process, we expect to get an exit code back once the process is finished and compare those codes in the powershell script to determine further steps to take and ultimately, relay that info back to SCCM.
What has recently (and possibly been going on longer than we realize) is that the Start-Process cmdlet doesn't return an exit code (it is null). We are checking to see if the exit code is equal to "0" and a variety of other possible values to see if the software has been installed or not. If the value is not in the list, the script assumes there was a problem and kicks back the error code to SCCM and stops the script from continuing. The real fun part is that it only happens intermittently. I have had a mix of computers (32/64-bit, VM/physical) side by side and there is no rhyme or reason as to which ones will succeed or fail. Remove the software and try again and I end up with different results.
Even though it errors, the software does get installed successfully. SCCM attempts to install the software again since it is out of compliance and finds that the software is already installed and ignores it (hence we don't know how long it has been going on). I have tested this code to be run from the Powershell ISE and it works great and returns an exit code every time. It is only in SCCM that we are having issues.
Thanks in advance!
See below what is going on:
$InstallCMD = "$sourcePath\jre-7u75-windows-i586.exe /s /v /norestart AUTOUPDATECHECK=0 IEXPLORER=1 MOZILLA=1 JAVAUPDATE=0 JU=0 SYSTRAY=0 /L*V $LogFile" #### A bunch of code that is working #### Write-Log -Message "Starting execution of the install command line" -Path $ScriptLog try { if($InstallCMD.Contains(' ')) { # Create the installer filepath and argument list from the $InstallCMD string $InstallerPath = $InstallCMD.Split(' ')[0] $InstallArgs = $InstallCMD.TrimStart("$InstallerPath ") Write-Host "InstallerPath: $InstallerPath" Write-Host "InstallerArgs: $InstallArgs" # Run the install command using the $InstallerPath and $InstallerArgs and capture the exit value of the installer $ExitVal = (Start-Process -FilePath $InstallerPath -ArgumentList $InstallArgs -PassThru -Wait -NoNewWindow).ExitCode } else { # Run the install command using the $InstallerPath and $InstallerArgs and capture the exit value of the installer $ExitVal = (Start-Process -FilePath $InstallCMD -PassThru -Wait -NoNewWindow).ExitCode } } catch { # There was an error running the install command line, log this then halt execution and return an error code Exit-OnError -ErrorVar $_ -Section "Install" } # Check if the install succeeded $Succeed = $False foreach ($SuccessVal in $SuccessCodes) { if ($ExitVal -eq $SuccessVal) {$Succeed = $True} } # If install failed script will halt execution and exit with that value if ($Succeed -eq $False) { Write-Log -Message "The installation did not succeed, the exit value was: $ExitVal" -Path $ScriptLog -Severity 3 Exit $ExitVal } else { Write-Log -Message "Finished execution of the install command line, the exit value was: $ExitVal" -Path $ScriptLog }