Tuesday, June 19, 2012

How to Have a Daily PowerShell Report of your Exchange 2007 backups sent to you everyday.

Have you ever needed a way to quickly tell what was going on with your Exchange 2007 backups at night when you are not in the office? I came up with this script back in 2010 that helps you do that using PowerShell combined with Scheduled tasks on a Windows Server. Tested on Exchange 2007 and PowerShell v1 and v2.

We do Full Backups daily but if you want to, you can add “LastIncrementalBackup”or “LastDifferentialBackup” to suit your needs.

Here is the script:
------------------------------------------------------------------------------------------------------------
#######################################
#Backup_report_vs1.ps1                #
#http://imjustanengineer.blogspot.com #
#Created by DJ 6/2/2010               #
#######################################

Add-PSSnapin Microsoft.Exchange.Management.powershell.admin;

Get-Mailboxserver | Get-MailboxDatabase -Status |FL Name,Server,lastfullbackup,backupinprogress,Mounted > c:\exch2007_backups.txt

start-sleep -s 120

$filename = “c:\exch2007_backups.txt”
$smtpServer = “your.smtpserver.com” #Enter FQDN of your SMTP server

$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($filename)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = “BackupReportingScript@yourdomain.com” #Enter senders email address $msg.To.Add(”recipient1@yourdomain.com, recipient2@yourdomain.com,”) #Enter one or more recipient addresses
$msg.Subject = “Exchange 2007 Servers Backup Report" #Enter subject of message $msg.Body = “Attached is the Daily Exchange 2007 Servers Backup Report. Please note any servers that have not been backed up for more than a day.” $msg.Attachments.Add($att)

$smtp.Send($msg)
-----------------------------------------------------------------------------------------------------------

In the created text file on your C: drive you should output that looks like

Name             : EXCH-SERVER01_SG01DB01
Server           : EXCH-SERVER01
LastFullBackup   : 6/7/2010 2:33:10 AM
BackupInProgress : False
Mounted          : True



Please let us know if this is helpful to you.  

No comments:

Post a Comment