0

I have a PowerShell script, at its begining I added: $ErrorActionPreference = "Stop". It's good, if there is an error the script won't go further. Fact is that when an error occurs, the script stop and exit itself and so, I can not see the error.

The best option is to crate a logfile that will write EVERYTHING that was in the PowerShell terminal, including succesful lines. If not, at least make the terminal keep opened even if an error occurs, but stop the script.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
xHypnosia
  • 79
  • 1
  • 2
  • 8
  • Possible duplicate of [What is the right way to do error handling in PowerShell?](https://stackoverflow.com/questions/1019213/what-is-the-right-way-to-do-error-handling-in-powershell) –  Jan 03 '19 at 13:38
  • 1
    It's a script right? What about try{} catch {} and logg the specific error? – guiwhatsthat Jan 03 '19 at 13:39
  • [This](https://stackoverflow.com/questions/53776641/how-do-i-create-log-file-time-user-who-run-the-script-and-what-happen-after-th/53776962#53776962) answers your question, but I agree that you are indeed looking for `try{} catch{}` – T-Me Jan 03 '19 at 13:48

1 Answers1

1

I would recommend Start-Transcript:

The Start-Transcript cmdlet creates a record of all or part of a PowerShell session to a text file. The transcript includes all command that the user types and all output that appears on the console.

Paweł Dyl
  • 8,888
  • 1
  • 11
  • 27