Skip to content

Instantly share code, notes, and snippets.

@ghotz
Created June 8, 2021 10:39
Show Gist options
  • Save ghotz/32935bd155990e158e0592147a35fdbc to your computer and use it in GitHub Desktop.
Save ghotz/32935bd155990e158e0592147a35fdbc to your computer and use it in GitHub Desktop.
Get list of SQL Servers from a Central Server and try sending a test mail for each server
# requires dbatools module
Get-DbaRegServer -SqlInstance localhost | % { write-host "testing $($_.ServerName)"; Invoke-DbaQuery -SqlInstance $_.ServerName -Query "DECLARE @sub nvarchar(max) = 'Test message from server ' + @@SERVERNAME, @bod nvarchar(max) = 'Test message sent by server ' + @@SERVERNAME + '.'; EXEC msdb.dbo.sp_send_dbmail @profile_name = 'SQL Server Admin', @recipients = '[email protected]', @subject = @sub, @body = @bod;" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment