I have a batch file: StartFile. bat
cd /d %~dp0
powershell.exe -File sp_script.ps1
pause
I have sp_script.ps1
$ErrorActionPreference;
sqlcmd -b -S myserver -d mydatabase -i sql_test_fail.sql | Tee-Object -file "sql_test_fail.txt" -ErrorAction Stop;
sqlcmd -b -S myserver -d mydatabase -i sql_test_pass.sql | Tee-Object -file "sql_test_pass.txt" -ErrorAction Stop;
Everything executes just fine. Creates the log files just fine.
However, at the failure of the execution of sql_test_fail.sql - I would like the batch execution to stop. It continues and executes sql_test_pass.sql.
I deploy sometimes as many as 100 scripts, and if one script errors I would like the batch to stop so I can investigate the error, and then continue upon restart.
I am very new to PowerShell any advice would be appreciated.