Weird thing going on here, maybe someone has seen it. I have a Powershell script that I have written that calls several executables. After the executable completes I want to retrieve the exit code for the executable so that I can note if it was successful for not. I'm told that $LastExitCode contains the exit code from the last Win32 app to execute. So I try it:
ping localhost
$lastexitcode
And the value returned is 0. Great!
Then I try:
GPUPDATE (while disconnected from the network, which should generate an error)
$lastexitcode
And the value returned is -1. Great!
So then I try to execute the same commands within my script. I can see the script waiting for the execution to complete before continuing, but this time when I ask for $lastexitcode I don't get a value (or it's null or similar). Any idea why?
________________________________________
CompTIA A+, Network+, Server+, Security+
MCTS:Windows 7
MCSE:Security 2003
MCITP:Server Administrator
MCITP:Enterprise Administrator
MCITP:Virtualization Administrator 2008 R2
Certified Quest vWorkspace Administrator
ping localhost
$lastexitcode
And the value returned is 0. Great!
Then I try:
GPUPDATE (while disconnected from the network, which should generate an error)
$lastexitcode
And the value returned is -1. Great!
So then I try to execute the same commands within my script. I can see the script waiting for the execution to complete before continuing, but this time when I ask for $lastexitcode I don't get a value (or it's null or similar). Any idea why?
Code:
Start-Process -FilePath C:\Windows\System32\ping.exe -ArgumentList 127.0.0.1 -NoNewWindow -Wait
"Did the last execution succeed? " + $?
$LastExitCode + "Is the last exit code" #why doesn't this work?
Start-Process gpupdate.exe -NoNewWindow -Wait
"Did the last execution succeed? " + $?
$LastExitCode + "Is the last exit code" #why doesn't this work?
________________________________________
CompTIA A+, Network+, Server+, Security+
MCTS:Windows 7
MCSE:Security 2003
MCITP:Server Administrator
MCITP:Enterprise Administrator
MCITP:Virtualization Administrator 2008 R2
Certified Quest vWorkspace Administrator