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.
Blog check…
Hello all,
I have an overall IT experience of about 6+ years now and I must say I’m a rookie when it comes to blogging. Although I’ve been an avid follower of several blogs and sites; I never imagined I could start one of my own. I guess I lacked that self-confidence…;-)
Ok with that said, here I am writing my very first blog. I was always amazed at how people can write such big blogs and used to wonder where they got all those words. So I would say I was kind of inspired by reading through the blogs of some of my peers. Before I get into any techie stuff, let me tell you guys who or what I am (btw I’m not a big shot or something).
My name is Nilesh Shetty. As I said earlier, I’ve have an overall IT experience of about 6+ years now and love what I am doing. The IT field kind of just happened to me…I never started off intending to land where I am today (I started off my career with Merchant Navy). After completing my diploma, I started off as a corporate trainer with a leading IT training company, and then moved onto the role of support engineer with Microsoft PSS group at a vendor site for Microsoft Exchange. After that I moved on to the role of a System Admin at an MNC company and at present working in the capacity of a Subject Matter Expert – Messaging and Collaboration in Bangalore.
About this blog, I would say that this would be a place where I would jot down my thoughts, my experiences, and the knowledge that I have gained so far in the field of Messaging and Collaboration (Mostly it would be related to Microsoft Technologies like Exchange, Active Directory, Windows, OCS etc). I hope it will help others and I would be glad to know that. Also I would invite all of you to provide a feedback and suggestions as to what you would like to see on this blog. Also at the same time, I would also say that this blog and its contents are provided “AS IS” with no warranties, and they confer no rights.