Reputation: 4244
I have a PS script which connects to MS SQL and makes changes in the DB and if the SQL script fails, my ps script still continues with the next steps. So I wonder what is a good way to stop the script after it failed on SQL side? My Powershell didn't recognize the normal abortion from SQL, so is the another way?
Upvotes: 0
Views: 260
Reputation: 41777
Take a look at $ErrorActionPreference. You can set this at a script level to Stop.
Upvotes: 1
Reputation: 5861
If you find a way to check if your SQL script worked or not (if you don´t know how you should provide a little more info on what you are doing), you can use Break
to stop your powershell script.
Upvotes: 1