Powershell 2.0 error handling - Command line call vs. ISE
- by Gromix
Hi,
In the context of deployment scripts, I would like to capture any error than happens and stop immediately.
I have notice some significant differences between the following calls:
powershell.exe -File Script.ps1
powershell.exe -Command "& '.\Script.ps1'"
powershell.exe .\Script.ps1
For example, the -File call will handle errors in the exact same way as the ISE. The other two seem to ignore the $ErrorActionPreference variable, and do not seem to catch Write-Error in try/catch blocks.
Could someone help me understand the implications of each one, and why they are behaving differently?
Thanks,
Romain