February 19th, 2016

PowerTip: Set ErrorActionPreference to original value

Doctor Scripto
Scripter

Summary: Cloud & Datacenter Management MVP, Thomas Rayner, shows how to work with the ErrorActionPreference variable in Windows PowerShell.

Hey, Scripting Guy! Question I have a script that requires me to change the ErrorActionPreference variable, but how can I set it to its original value after the script is done?

Hey, Scripting Guy! Answer Store the current value of $ErrorActionPreference and set it again later:

$OldEAP = $ErrorActionPreference

$ErrorActionPreference = ‘silentlycontinue’

#Your script runs in here

$ErrorActionPreference = $OldEAP

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.

Feedback