Powershell Errors out correctly in ISE but doesnt in Command line execution -


I'm running a command in powershell ISE which was exiting how I expected, but when I command the code Taken in the line executed in different environments, I was not getting any further error. The error is only in ISE I have tried to use - like the posts of others -sta on the command line, but the luck has not happened. Exchange code: $ lastExitCode - return code: $? "

When ISE I get the following output:

  Exit code: 0 - return code: wrong   

When I command that command on the command line I get the following output:

  e: \ powershell.exe -sta-file script.ps 1 exit code: 0 - return code: true   

As you can see, I can check the return code Area and trying to do the right action at the ISE, but not get the right results through the command line.

I am thinking that the various environment variables using Windows while running in ISE are variable ones. I think that when I run it through ISE, the console shows errors in red.

$? variable only checks the status of the success of the last PowerShell command executed, not external executable.

$ LASTEXITCODE variable detects the final exit code from external execution

As you can see, these variables are used for various purposes , So you will not see stability between them. For more information about them, run this command:

 get  -name_automatic_varyables   

Edit: to display $ code Run? The variable works.

  Here we will show a successful command, and then fail to write the failed .NET method call "Hi"; #Write a successful command - host-object $?; # True = command successful [System.IO.File] :: NonExistentMethod (); Write-host-object $?; # False = command fail # Here we will show a successful command, then write a failed executable call-output-object "Hi". Out of naught; #Write a successful command - host-object $?; # True = The last command successfully ipconfig / nonexistentparameter | Gone out null; Write-host-object $?; # False = The last command did not run successfully   

For me, the PowerShell v3 release candidate is running, it works similarly in the console as ISE.

Comments