Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

Autoalert if SQLAgent stops

$
0
0
I have this piece of powershell code which sends out an email when executed in a SQL job or run in powershell mode but does not work in this below situation.Attached is a screenshot of the Recovery tab under SQLAgent services.I have run this command in powershell before stopping SQLAgent but I did not get any email alert that the SQLAgent has been stopped.set-executionpolicy remotesignedCan anyone help fix this?Thanks#variables$emailFrom = "defg@kjid.org"$emailTo = "abcd@def.org"$subject = "Powershell Function calling an SMTP server"$body = "Send an email through SMTP in Powershell"$smtpServer = "smtp.abcdefgh.org"#create a functionFunction sendEmail([string]$emailFrom, [string]$emailTo, [string]$subject,[string]$body,[string]$smtpServer){$smtp = new-object Net.Mail.SmtpClient($smtpServer)$smtp.Send($emailFrom,$emailTo,$subject,$body)}sendEmail $emailFrom $emailTo $subject $body $smtpServer

Viewing all articles
Browse latest Browse all 467

Trending Articles