I was looking for a free solution to have email notifications for Azure backup. After reading other blogs and technet site I end up to use PowerShell Send-MailMessage attached to the Azure Backup Logs. In short, when the Azure Backup log is created, the script lists the last 2 days events, creates an html file and mails the report with the html as attachment to you.
First find the Azure backup Event Log, it under “Applications and Services Logs, CloudBackup, Operational” and select to attach a task to the log. This will trigger the task on every event created under this log. On the other hand you can attach the task to a specific event.
Create a Task and attach the below PowerShell script. Here you will find the powershell.exe “C:WindowsSystem32WindowsPowerShellv1.0”
Crate a folder c:\IT and Copy the below script on a text file and name it “eventemail.ps1”. Finally change the required fields.
$date = (Get-Date).AddDays(-2) $event = Get-WinEvent -FilterHashtable @{ LogName = "cloudbackup"; StartTime = $date; } $event | ConvertTo-Html message,timecreated | Set-Content c:itbackup.html if ($event.EntryType -eq "Error") { $PCName = $env:COMPUTERNAME $EmailFrom = "FROM_EMAIL_HERE" $EmailTo = "YOUR_EMAIL_HERE" $EmailSubject = "Server $PCName Backup Failure report" $SMTPServer = "SMTP_SERVER_HERE" Write-host "Email Sent" Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -body "$($event.Message) $($event.TimeCreated)" -Attachments "c:itbackup.html" -SmtpServer $SMTPServer } else { write-host "There is no error. Below the logs files." $event $PCName = $env:COMPUTERNAME $EmailFrom = "FROM_EMAIL_HERE" $EmailTo = "YOUR_EMAIL_HERE" $EmailSubject = "Server $PCName Backup Success report" $SMTPServer = "SMTP_SERVER_HERE" Write-host "Sending Email" Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -body "$($event.Message) $($event.TimeCreated)" -Attachments "c:itbackup.html" -SmtpServer $SMTPServer }
The “write-host ” lines can be removed. They are useful only for troubleshooting by running the script manually on powershell.
Pantelis Apostolidis is a Sr. Specialist, Azure at Microsoft and a former Microsoft Azure MVP. For the last 20 years, Pantelis has been involved to major cloud projects in Greece and abroad, helping companies to adopt and deploy cloud technologies, driving business value. He is entitled to a lot of Microsoft Expert Certifications, demonstrating his proven experience in delivering high quality solutions. He is an author, blogger and he is acting as a spokesperson for conferences, workshops and webinars. He is also an active member of several communities as a moderator in azureheads.gr and autoexec.gr. Follow him on Twitter @papostolidis.