$Lastexitcode is null

Apr 26, 2010 at 2:17 PM
Edited Apr 26, 2010 at 2:18 PM

I am testing the auto script. I have noticed the $lastexitcode is alway null. Why would the value be null always? Here is an example. I know the Hotfix is already installed. I step through the step - after envoking Start-Process "D:\Hotfixes\$WCFHotfix" -ArgumentList "/quiet /promptrestart" -Wait i would think that the $lastexitcode value would be 87 - it is not.

Function Install-WCFHotfix { If ($OS -eq "Win2008") {$WCFHotfix = "Windows6.0-KB971831-x64.msu"} ElseIf ($OS -eq "Win2008R2") {$WCFHotfix = "Windows6.1-KB976462-v2-x64.msu"} Write-Progress -Activity "Installing Prerequisite Software" -Status "Please Wait..." -CurrentOperation "$WCFHotfix for $OS" Write-Host -ForegroundColor Blue " - WCF hotfix for $OS..." try { Start-Process "D:\Hotfixes\$WCFHotfix" -ArgumentList "/quiet /promptrestart" -Wait If (-not $?) {throw} } catch { If ($LASTEXITCODE -eq "87") {Write-Host -ForegroundColor Blue " - $WCFHotfix already installed"} ElseIf ($LASTEXITCODE -eq "1641") { Write-Host -ForegroundColor Yellow " - You should restart your server NOW for the hotfix to take effect." Write-Host -ForegroundColor Yellow " - You can re-run the script again once you've rebooted." CMD.EXE /C pause exit } ElseIf ($LASTEXITCODE -eq "5") {throw " - Local Administrator permissions are required to proceed!"} ElseIf ($LASTEXITCODE -eq "-2145124329") {throw " - $WCFHotfix not applicable to your system (is .NET framework installed?)"} ElseIf (($LASTEXITCODE -ne "2359302") -and ($LASTEXITCODE -ne "87")) { Write-Host -ForegroundColor Red "- Error: $LASTEXITCODE" throw "- An unknown error ($LASTEXITCODE) occurred installing the $OS hotfix" } } }

Apr 26, 2010 at 3:29 PM
Edited Apr 26, 2010 at 3:30 PM

I just tested this quickly and you're right - $lastexitcode (or $LASTEXITCODE or $LasTeXiTcODE, etc.) would always be null. See where I'm getting at? Turns out this variable (an Automatic Powershell variable) is case sensitive - go figure! I'm going to update the script to use $LastExitCode instead, and that should behave much better... There will be an updated release in the coming days with this fix.



Apr 26, 2010 at 5:41 PM

After more testing it seems that even with the correct case, $LastExitCode returns null. Not sure why but still investigating.