Updated 14/01/2013 to version 1.3 with some minor bug fixes and improvements to the script. If you are already running an older version of this script please re-read the usage instructions as they have changed a little.
In recent articles I’ve taken you step by step through some techniques for sending email from PowerShell scripts. If you haven’t read those articles yet you can find them here:
- Part 1 – How to Send SMTP Email Using PowerShell
- Part 2 - How to Add a Message Body to Emails Sent from Scripts
- Part 3 - How to Add a HTML Message Body to Emails Sent from Scripts
- Part 4 - How to Create Formatted HTML Output from Scripts
I also shared with you a script that can be used to check Exchange Server 2010 database backups and alert you to any that have not had a recent backup.
Now it’s time to bring all of that information together and demonstrate how you can set up an automated database backup alert email for your Exchange Server 2010 environment.

The two components of this are:
- The PowerShell script itself (we’ll use the one mentioned earlier but with some modifications to email-enable it)
- Task Scheduler for automatically running the script each day
Download the script file here: Get-DailyBackupAlerts.ps1 (downloaded 2125 times so far)
If you’re using this script in your environment you will need to change the SMTP options to suit.
#................................... # Modify these SMTP settings to suit # your environment #................................... $smtpServer = "smtp.exchangeserverpro.net" $smtpFrom = "exchangeserver@exchangeserverpro.net" $smtpTo = "administrator@exchangeserverpro.net"
If the SMTP server you specify is valid but no emails are being sent you may need to configure a relay connector or add the IP address of the workstation/server that is running the script to an existing relay connector.
You can also modify the alert thresholds.
#...................................
# Modify these alert thresholds to
# suit your needs
#...................................
#You can set a different alert threshold for Mondays
#to account for weekend backup schedules
$day = (Get-Date).DayOfWeek
if ($day -eq "Monday")
{
[int]$threshold = 48
}
else
{
[int]$threshold = 24
}
Finally, if there are databases in your Exchange environment that are never backed up, you can exclude those from the report entirely.
#...................................
# If you wish to exclude databases
# from the report add them here
#...................................
#Example: $excludedbs = @("database1","database2")
Save the script as Get-DailyBackupAlerts.ps1 in a folder called C:\Scripts on the server where you would like it to run each day. Note that the script depends on the Exchange Server 2010 management tools, so they will also need to be installed.
You can run the script manually using the -Verbose (provides useful output for troubleshooting) and -AlwaysSend (sends the email report even if there are no alerts) switches as a test to ensure that it runs correctly.

Change Log:
- V1.0 – 30/4/2012 – Initial version
- V1.1 – 25/10/2012 – Minor bug fixes and improvements
- V1.2 – 30/10/2012 – Fixed bug with alertflag
- V1.3 – 13/01/2013 – Many code improvements, more comments, archive mailboxes now counted, and added option to always send the report regardless of number of alerts.
Download the script file here: Get-DailyBackupAlerts.ps1 (downloaded 2125 times so far)
Using Task Scheduler to Run PowerShell Scripts
Now we need to configure the scheduled task in Task Scheduler. On a Windows Server 2008 server you’ll find this in the Administrative Tools. After you’ve launched Task Scheduler click on Create Task.
Give the task a meaningful name, set it to Run whether user is logged on or not, and also if necessary change the user account that it will run as (you may wish to create a special Exchange administrative account with a strong password for running these types of scripts).
On the Triggers tab click new and add a Weekly trigger for each of your normal business days that you want the script to run (eg Monday – Friday). Set the Start time to suit your normal backups finishing time and your own work schedule.

On the Actions tab click New and add an action of Start a program. Configure the program of powershell.exe and the arguments -command “c:\scripts\get-dailybackupalerts.ps1 -AlwaysSend” instead.
If you would prefer the script always sends the report even if there are no alerts, then use the arguments -command “c:\scripts\get-dailybackupalerts.ps1″

Click OK to finish creating the new task. You will be prompted to enter the credentials for the account that you configured the task to run as.
Now you can test the scheduled task by right-clicking on it in the Task Scheduler Library and choosing Run.
Assuming you have some databases that have not backed up recently you should receive an alert email shortly after running the scheduled task.

Note: if your backups are all up to date you can test the script by either changing the $threshold variable to something very low such as 1 (ie 1 hour) so that it will trigger an alert, or using the -AlwaysSend switch.
Download the script file here: Get-DailyBackupAlerts.ps1 (downloaded 2125 times so far)




Will this script work with Exchange 2007?
Should work pretty well, possibly just need a few modifications around the Server/DAG name detection and how it handles public folders vs mailbox databases.
Could just simplify that If/Else block down to just use $db.Server regardless of whether it is PF or MB database.
Hello,
If I run manually it works great. If run from a batch file or via scheduler, the email does not list the db and is generally blank. Suggestions?
Wally Hass
Possible that the credentials being used to run the scheduled task do not have access to Exchange.
Paul, a brilliant script, who hasn’t been caught out with logs files at some point!!!
Such a indicates that to acquire with each other coupled, the particular way powerful. Attached to an added spot, Jimmy Choo Shoes UK taking care for the views, we need to will depend on really information on everyday, significant amounts of things. Which include, Shen Lin contamination, the most important substance labor and birth results of water, need to get that you look after. Data associated with this well being, it ought to be a man or woman of your side, well then in, the feelings are going to significant. Folks believe long-distance romance on e-commerce conversation, video playback Jimmy Choo also a solution to boost their inner thoughts. At the start of point, happy with all new, rather always experience one another’s a tasty, having said that after, you’ll certainly be weary. Because plenty pledge are really unreal, the different sweet taste at all bubbles http://www.jimmychooshoesale.co.uk/ .
When i try to run this script it says it is not signed.. i can ofcourse lower my guard and have exection policy set to unrestricted but it would be neater to have this script trusted by my servers.. how do i set that option?
I just came across this and am attempting to shoehorn this into my Exchange 2007 environment. I’ve got it to run and email without a problem. I’ve loaded the Exchange 2007 PS addin to PS. However, the report neglects to include the server/dag and database type in those sections.
When I run the commands to get the list of databases and their status…it lists everything as expected. Any hints?
Thanks again for a wonderful script!
I got it going. Exchange 2007 doesn’t allow have IsMailboxDatabase/IsPublicFolderDatabase equals True/False as a valid database property. I manually used:
db.Name -eq “Name of my Mailbox Database”) {$dbtype = “Mailbox”}
and
db.Name -eq “Name of my PF Database”) {$dbtype = “Public Folder”}
At that point, I ignored some of the logic for what gets set in the server/dag value column of the report. db.MasterServerOrAvailabilityGroup isn’t a valid property for me, so I simply used used db.Server to fill in the Server/DAG value.
I then included:
$dbObj | Add-Member NoteProperty -Name “Storage Group” -Value $db.StorageGroup.Name
to give me the Storage Group Name where my Mailbox Database resides.
Seems to work great. i adjusted the Monday threshold to 48 hours and all other days’ threshold to 24. updated the comments to match..”This will go out if a backup hasn’t been done in more than 24 hours”.
One thing to note…i have a couple spam mailboxes that I don’t back up…i keep rolling logs on it. That mailbox database hasn’t been backed up…even though it would come back with never, the email never goes out. Shouldn’t it email if a database (MB or PF) hasn’t been backed up?
I got the script to work for testing purposes with the threshold set to 1hr. But now when I change the script’s threshold to 10, it checks the databases and does not send an email.
I ran the powershell commands manually and have databases that were last backed up over 24 hours ago.
Shouldn’t the script still send an email?
There was a bug with the script that should fix that. I recommend trying the latest version.
This works great but I have a database that is currently being backed up but is not being reported. I’d like to convert this to more of a database backup report. Database xyz has not been backed up database abc backup is in progress and then database 123 was completed on…
My problem is that I am not that versed in power shell. Any guidance would be welcome.
Thanks
Paul
Hi Paul, I would like to know, in which language this screept has been written ?
Powershell.
Hi Paul, Thanks for the script, works like a charm… when you say that the databases haven’t been backed up… what do you mean by that?
If a daily Windows Server Backup is performed… should this reflect it? Or still there is a better procedure to backup the Exchange databases?
Thanks.
Can some one post a working exchange 2007 version of this script?
should it work on windows server 2008 R2 for both Active Director and File Server Backup?
Is there a way to use a variable so that the script takes the SMTP server settings from the local exchange server it is running on?
Ex.
$smtpServer = “localhost”
$smtpFrom = “administrator@%Domain%”
Thanks,
Carl
Paul,
Great script. This was exactly what I was looking for. Just one question on the latest version. I have about 68 existing Exchange 2007 DBs I would like to exclude, but have not been able to successfully exclude them in the script unless I type out the entire “server\sg\db” format in the exclude DBs section. I do not want to type out all 68 2007 DBs. Is there another way to exclude these DBs from the report?
Thanks,
Johnny
Whether you type them in the script or type them in a txt file that the script references, one way or the other you’re still typing them out.
Unless you have some other criteria you can filter them out with (eg a common string in their names or which server they sit on).
Yes, it’s great script.. A question only.. it’s possible to include and size of last backup session..?
That info would normally come from your backup product. It isn’t stored in Exchange.
Great Script Paul. It runs on screen but get the below errors right at the end.
I used the -verbose -alwayssend options.
New-Object : Exception calling “.ctor” with “2″ argument(s): “The specified string is not in the form required for an e
-mail address.”
At C:\apps\BackupAlert.ps1:314 char:23
+ $message = New-Object <<<< System.Net.Mail.MailMessage $smtpfrom, $smtpto
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Property 'Subject' cannot be found on this object; make sure it exists and is settable.
At C:\apps\BackupAlert.ps1:315 char:11
+ $message. <<<< Subject = $messageSubject
+ CategoryInfo : InvalidOperation: (Subject:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'IsBodyHTML' cannot be found on this object; make sure it exists and is settable.
At C:\apps\BackupAlert.ps1:316 char:11
+ $message. <<<< IsBodyHTML = $true
+ CategoryInfo : InvalidOperation: (IsBodyHTML:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'Body' cannot be found on this object; make sure it exists and is settable.
At C:\apps\BackupAlert.ps1:317 char:11
+ $message. <<<< Body = ConvertTo-Html -Body "$intro $summary $alertintro $alerthtml $okintro $okhtml $outro" -Head
$style
+ CategoryInfo : InvalidOperation: (Body:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
VERBOSE: Sending email report
Exception calling "Send" with "1" argument(s): "Value cannot be null.
Parameter name: message"
At C:\apps\BackupAlert.ps1:322 char:12
+ $smtp.Send <<<< ($message)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
“The specified string is not in the form required for an e -mail address.”
Are you using a string that is a valid email address?
Yeah I am using a valid email address, server, etc.. I just modified the below to suit with my details.
$smtpServer = “smtp.exchangeserverpro.net”
$smtpFrom = “exchangeserver@exchangeserverpro.net”
$smtpTo = “administrator@exchangeserverpro.net”
For whatever reason, the script has started to work and there arent any errors anymore.
thank you.
Is there a way to color code the background of the Status ?
Alert = Red
OK = Green
Paul,
Please help me still i am facing this issue.
Thank You
Sreejith