0
votes

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.

1
Possible duplicate of What is the right way to do error handling in PowerShell?user6811411
It's a script right? What about try{} catch {} and logg the specific error?guiwhatsthat
This answers your question, but I agree that you are indeed looking for try{} catch{}T-Me

1 Answers

1
votes

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.