Created
June 8, 2021 10:39
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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