Home > Powershell > [PS] Write powershell errors to a text file

[PS] Write powershell errors to a text file

Method 1: Try, Catch, Finally

Try: Try to execute a command
Catch: Catches any errors, triggers only for Terminating Errors, so you may need to set a ErrorAction -Stop (EA) for errors that are not terminating.
Finally: Runs regardless if a error occurs.

Method 2: Output error directly to error log 

Method 3: Customize a out-file to a error log

 

Categories: Powershell Tags:
  1. No comments yet.
  1. No trackbacks yet.