Jump to content













Photo
- - - - -

Azure Backup Email Notification

Posted by Pantelis Apostolidis , in Azure 19 December 2014 · 1,808 views

azure backup powershell

I was looking for a free solution to have an 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:\Windows\System32\WindowsPowerShell\v1.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:\it\backup.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:\it\backup.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:\it\backup.html" -SmtpServer $SMTPServer
}

 

The “write-host ” lines can be removed. They are useful only for troubleshooting by running the script manually on powershell.

 

source: http://www.e-apostol...l-notification/