I have a Powershell .ps1 script that is run through the Exchange Management Shell. When testing and writing the script, it worked perfectly. Cmdlets inside try blocks with "-ErrorAction 'stop'" properly go into the catch block on error.
However, when the script is run through the Exchange Management Shell, errors do not properly fall into the catch. The -ErrorAction on the cmdlets might as well be 'continue', they output to screen and continue on as if there was no error, so the catch block isn't run at all.
Why does the script run in the EMS not properly catch errors, when it does catch errors when run in the Powershell ISE or the regular Powershell shell/CLI?