I have written powershell script that executes all sql from folder, but I want to stop executing on error? Is it possible to catch the error with powershell that was happened on SQL server? This is powershell code
function runSqlScript{
param([string]$sqlPath)
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString.connectionString
$connection.Open()
$command = $connection.CreateCommand()
$command.CommandText = Get-Content $sqlPath
$command.ExecuteNonQuery()
$connection.Close()
}
function runScriptsFromFolder{
param( [string]$pathToFolder)
Get-ChildItem $pathToFolder -Filter *.sql| ForEach-Object {
runSqlScript($_.FullName)
}
}
Invoke-notrun