Azure PowerShell 虚拟机警报电子邮件功能
Azure PowerShell Virtual Machine alert email function
只是想知道是否有人有任何 PowerShell 代码片段可以在虚拟机启动时发送电子邮件通知用户并通过自动 运行 书解除分配?
其余的我都有了,但只是想为此添加电子邮件代码功能。
Just wondering if anyone has any PowerShell code snippets which can
ping an email informing the user when their Virtual Machine starts and
deallocates through an automated Run Book?
如果您想使用 Runbook 发送电子邮件,我们应该先有一个 SMTP 服务器。
然后我们可以使用PowerShell命令来完成:
Send-MailMessage
更多关于Send-MailMessage
的信息,请参考这篇link。
另一种方式,我们可以使用Azure SendGrid Service发送邮件,这里是powershell脚本:
$Username ="YourUserName"
$Password = ConvertTo-SecureString "AddYourPasswordHere" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $Username, $Password
$SMTPServer = "smtp.sendgrid.net"
$EmailFrom = "No-reply@azureadmin.com"
[string[]]$EmailTo = "AddToEmailAddressessHere. To add multiple use comma separated values."
$Subject = "Sending sample email using SendGrid Azure and PowerShell"
$Body = "This is sample email sent using Sendgrid account create on Microsoft Azure. The script written is easy to use."
Send-MailMessage -smtpServer $SMTPServer -Credential $credential -Usessl -Port 587 -from $EmailFrom -to $EmailTo -subject $Subject -Body $Body -BodyAsHtml
Write-Output "Email sent succesfully."
关于创建Azure sendgrid服务,请参考这个article。
我们还可以使用 Azure activity 日志警报 向您发送邮件,有关创建 activity 日志警报的更多信息,请参阅此 link.
希望对您有所帮助。
还有一个巨大的 Azure 自动化运行手册库,由 Microsoft 和社区创建。您可以阅读有关 Azure 自动化的 Runbook 和模块库 here. The actual gallery items can be found here。
只是想知道是否有人有任何 PowerShell 代码片段可以在虚拟机启动时发送电子邮件通知用户并通过自动 运行 书解除分配?
其余的我都有了,但只是想为此添加电子邮件代码功能。
Just wondering if anyone has any PowerShell code snippets which can ping an email informing the user when their Virtual Machine starts and deallocates through an automated Run Book?
如果您想使用 Runbook 发送电子邮件,我们应该先有一个 SMTP 服务器。
然后我们可以使用PowerShell命令来完成:
Send-MailMessage
更多关于Send-MailMessage
的信息,请参考这篇link。
另一种方式,我们可以使用Azure SendGrid Service发送邮件,这里是powershell脚本:
$Username ="YourUserName"
$Password = ConvertTo-SecureString "AddYourPasswordHere" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $Username, $Password
$SMTPServer = "smtp.sendgrid.net"
$EmailFrom = "No-reply@azureadmin.com"
[string[]]$EmailTo = "AddToEmailAddressessHere. To add multiple use comma separated values."
$Subject = "Sending sample email using SendGrid Azure and PowerShell"
$Body = "This is sample email sent using Sendgrid account create on Microsoft Azure. The script written is easy to use."
Send-MailMessage -smtpServer $SMTPServer -Credential $credential -Usessl -Port 587 -from $EmailFrom -to $EmailTo -subject $Subject -Body $Body -BodyAsHtml
Write-Output "Email sent succesfully."
关于创建Azure sendgrid服务,请参考这个article。
我们还可以使用 Azure activity 日志警报 向您发送邮件,有关创建 activity 日志警报的更多信息,请参阅此 link.
希望对您有所帮助。
还有一个巨大的 Azure 自动化运行手册库,由 Microsoft 和社区创建。您可以阅读有关 Azure 自动化的 Runbook 和模块库 here. The actual gallery items can be found here。