Home > Powershell > How To: Generate an automated Email with Backup Status Report for Exchange 2007 and 2003 Servers using Powershell

How To: Generate an automated Email with Backup Status Report for Exchange 2007 and 2003 Servers using Powershell

Frequent backups of the Exchange servers in an organization are important operational tasks that, though a bit trivial, should be taken very seriously. I can only imagine one thing worse than a complete failure of an Exchange 2007 server, and that’s a complete failure of an Exchange 2007 server without any backups to restore from. As an adminstrator, you need to make sure that the backups are being taken successfully everyday.

Given below is a script which will generate a status report and will send an email with regards to the same. Note that I have selected the property “LastFullBackup” only assuming that a full backup of the server database is taken everyday. If you want, you can add “LastIncrementalBackup” and/or “LastDifferentialBackup” in the list.

———————————————————————————————————————————————————————————

$MBXStatus = Get-ExchangeServer | where{$_.serverrole -match “mailbox” -or $_.admindisplayversion -like “Version 6.5*”} | Get-MailboxDatabase -status | Select Servername,Identity,Lastfullbackup,BackupinProgress | Sort-object LastFullBackup
$PFStatus = Get-ExchangeServer | where{$_.serverrole -match “mailbox” -or $_.admindisplayversion -like “Version 6.5*”} | Get-PublicFolderDatabase -status | Select Servername,Identity,Lastfullbackup,BackupinProgress | Sort-object LastFullBackup

$Header = “<style>table {font-size: 11pt; font-family: calibri;}
  body {background-color:black;}
  table {align: center; border-width: 1px;border-style: solid; border-color: black; border-collapse: collapse;}
  th {font-size:1.5em; border-width: 1px;padding: 2px; border-style: solid; border-color: white; background-color: #FFCCCC}
  td {font-size:1.2em; border-width: 1px;padding: 2px; border-style: solid; border-color: white; background-color: PaleGoldenRod}
</style>”
$Body = “Exchange Server Backup Status Report”

$SmtpServer = “<Hub Transport Server>”
$From = “<Email Id>”
$To = “<Email Id>”
$Sub = Date
$Subject = “Exchange Server Backup Report – “  +  $Sub

$Messages = $MBXStatus + $PFStatus
$MessageBody = $Messages | ConvertTo-Html -Head $Header -Body $Body

$MailMessage = New-Object Net.Mail.MailMessage($From, $To)
$MailMessage.Subject = $Subject
$MailMessage.IsBodyHtml = $True

$HtmlView = [Net.Mail.AlternateView]::CreateAlternateViewFromString($MessageBody, “text/html”)
$MailMessage.AlternateViews.Add($HtmlView)

(New-Object Net.Mail.SmtpClient($SMTPServer)).Send($MailMessage)
Exit

———————————————————————————————————————————————————————————

There are of course other ways of doing this, however I find this one is the most suitable for me and my environment. It will also give you the information regarding the databases on Exchange 2003 versions too including both Mailbox Store as well as Public Folder Store.

You can save the above script in a notepad as a .ps1 file and schedule it to run on any machine which has Powershell and Exchange 2007 Management tools. For more information regarding how to schedule a powershell script to run at a specific time, you can refer to my next post.

  1. No comments yet.
  1. No trackbacks yet.