Powershell 2.0 error handling - Command line call vs. ISE
Posted
by Gromix
on Stack Overflow
See other posts from Stack Overflow
or by Gromix
Published on 2010-05-24T03:48:34Z
Indexed on
2010/05/24
3:50 UTC
Read the original article
Hit count: 353
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
© Stack Overflow or respective owner