Responding to my blog entry on -ErrorAction HERE, Jon Newman reminded me that the reason we didn’t use the term IGNORE for -ErrorAction was that we don’t really ignore the error. We still record it in $ERROR.
He also reminded me that I should have talked about $ErrorActionPreference. This variable defines the action that will occur if the user does NOT specify what to do on the commandline. Check it out:
PS>$ErrorActionPreference
Continue
PS>Stop-Process 13,23
Stop-Process : Cannot find a process with the process identifier 13.
At line:1 char:13
+ Stop-Process <<<< 13,23
Stop-Process : Cannot find a process with the process identifier 23.
At line:1 char:13
+ Stop-Process <<<< 13,23
PS>$ErrorActionPreference ="SilentlyContinue"
PS>Stop-Process 13,23
PS>$ErrorActionPreference ="Stop"
PS>Stop-Process 13,23
Stop-Process : Command execution stopped because the preference variable "ErrorActionPreference" or common parameter i
set to Stop: Cannot find a process with the process identifier 13.
At line:1 char:13
+ Stop-Process <<<< 13,23
PS>$ErrorActionPreference ="Inquire"
PS>Stop-Process 13,23
Confirm
Cannot find a process with the process identifier 13.
[Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is "Y"): h
Stop-Process : Command execution stopped because the user selected the Halt option.
At line:1 char:13
+ Stop-Process <<<< 13,23
Enjoy!
Jeffrey Snover [MSFT]
Windows Management Partner Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx
0 comments