Basically, I want to be able to catch the warnings returned from Invoke-SqlCmd without having to stop the script running. The following code does not work:
TRY {
Invoke-SQLCMD -Query "selects * from syscomments" -ServerInstance $ServerAddress -Database $DatabaseName -ErrorAction 'SilentlyContinue'
}
CATCH {
Write-Host "[!] Errors returned, check log file for details" -ForegroundColor RED
$_ | Out-File -Append "path to log"
}
This just suppresses all output and doesn't catch the error. Changing the error type to Stop does catch the error but I need these scripts to continue running after an error is hit.