Skip to content

Instantly share code, notes, and snippets.

@ghotz
Last active June 4, 2021 14:45
Show Gist options
  • Save ghotz/e4612e795717e337ee2781c5ae1cdb45 to your computer and use it in GitHub Desktop.
Save ghotz/e4612e795717e337ee2781c5ae1cdb45 to your computer and use it in GitHub Desktop.
Various Alerts related
# quick fix for Copy-DbaAgentAlert not copying categories (and Copy-DbaAgentAlertCategories not existing)
param ([string] $Source, $Destination)
Get-DbaAgentAlertCategory -SqlInstance $Source | % { New-DbaAgentAlertCategory -SqlInstance $Destination -Category $_.Name};
Copy-DbaAgentAlert -Source $Source -Destination $Destination;
SELECT
M1.message_id, M1.severity, M1.[text]
, 1 AS is_error_alert, 0 AS is_severity_alert
FROM dbo.sysalerts AS A1
JOIN sys.messages AS M1
ON A1.message_id = M1.message_id
WHERE M1.language_id = 1033
AND A1.[enabled] = 1
UNION ALL
SELECT
M1.message_id, M1.severity, M1.[text]
, 0 AS is_error_alert, 1 AS is_severity_alert
FROM dbo.sysalerts AS A1
JOIN sys.messages AS M1
ON A1.severity = M1.severity
WHERE M1.language_id = 1033
AND A1.[enabled] = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment