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.

3
  • Possible duplicate of What is the right way to do error handling in PowerShell? Commented Jan 3, 2019 at 13:38
  • 1
    It's a script right? What about try{} catch {} and logg the specific error? Commented Jan 3, 2019 at 13:39
  • This answers your question, but I agree that you are indeed looking for try{} catch{} Commented Jan 3, 2019 at 13:48

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.