I’m using powershell script to run a few *.sql file. I can get the output value by using the script below..
$return_value = sqlcmd -S ServerName -i "MyAwesome.sql" -v parameter1="par1"
The problem is that I will have to extract out the output text to determine whether there is any error in SQL file or not..
Is there any best practice to handle the exceptions in powershell file and *.sql file?
Do I have to catch the error in each and every SQL files to produce the pre-defined output?
Might not be an option for you, but the Invoke-SqlCmd cmdlet has a parameter called “-ErrorVariable” to trap error messages.