powershell - How to log an eventlog only when the script gives a red error? -


what want - log event in eventlog - application, when scheduled script gives red error in session...

i know how log write-eventlog, cant limit when gives red error saying maybe wrong.

your response appreciated!

one way clear $error before statemtent, check if error occurred:

$error.clear() invoke-something if ($error.count -gt 0) {   write-eventlog ... } 

or turn errors terminating errors , use try..catch statement:

$eap = $erroractionpreference $erroractionpreference = 'stop' try {   invoke-something } catch {   write-eventlog ... } $erroractionpreference = $eap 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -