This script demonstrates a concept, but if you want a more complete working script use Get-DailyBackupAlerts.ps1 instead.
Here is a simple script you can use to check the last backup time for the mailbox databases on an Exchange Server. Run the script from the Exchange Management Shell on a Mailbox Server to check the local server’s databases.
[PS] C:Scripts>.check-dbbackups.ps1 Server: ESP-HO-EX2010B Current time: 03/27/2011 22:21:39 Database Last Full (hrs ago) Last Inc (hrs ago) -------- ------------------- ------------------ MB-HO-01 1 n/a MB-HO-02 1 n/a MB-HO-Archive-01 n/a n/a
Here is the script code.
$server = $env:computername $now = [DateTime]::Now "Server: " + $server "Current time: " + $now $db = get-MailboxDatabase -server $server -status foreach ($objItem in $db) { $lastfull = $objItem.lastfullbackup if (!$lastfull) { $fullago = "n/a" } else { $fullago = $now - $lastfull $fullago = $fullago.TotalHours $fullago = "{0:N0}" -f $fullago } $lastinc = $objItem.lastincrementalbackup if (!$lastinc) { $incago = "n/a" } else { $incago = $now - $lastinc $incago = $incago.TotalHours $incago = "{0:N0}" -f $incago } $returnedObj = new-object PSObject $returnedObj | add-member NoteProperty -name "Database" -value $objItem.Name $returnedObj | add-member NoteProperty -name "Last Full (hrs ago)" -value $fullago $returnedObj | Add-Member NoteProperty -name "Last Inc (hrs ago)" -value $incago $returnedObj }
Hello Paul
This is Abhishek from New Delhi/ India. Your Script works great in our envt. Thanks for this wonderful script
I am newbie to Powershell, so don’t know much about it, In the Database Backup Alert Email, can you also advise me where to add the field of Last Incremental Backup, Size of databases, space remaining on the drives and threshold of 1 week alert .
Thanks
Thanks
I recommend you look at this script instead:
https://www.practical365.com/set-automated-exchange-2010-database-backup-alert-email/
If it doesn’t do exactly what you need then it is quite simple to modify it.
Hi Paul,
How to check last backup per user mailbox not database mailbox ? could this script can do that ?
Thank you
I don’t know what you mean by that. A database is a database.
What do “user mailbox” and “database mailbox” mean to you?
Hi Paul,
I mean how to see the last backup per user mailbox with use this script. it is posibble ?
Thank You
Mailboxes are hosted in databases. Databases are backed up. This script reports on the backup times for databases.
If you want to know which database a mailbox is located in you can run Get-Mailbox to see that information.
Pingback: Powershell Backup Mailbox To Pst | OutlookRecoveryGuide.org
This was helpful for me… I wanted the script to run, on a click, and wait for me to read the results before closing…
Open notepad, paste the code below in…
Save as something nifty like: “Check Exchange Last Backup.PS1”
——————————————————————————————-
add-pssnapin Microsoft.Exchange.Management.PowerShell.SnapIn
$server = $env:computername
$now = [DateTime]::Now
“Server: ” + $server
“Current time: ” + $now
$db = get-MailboxDatabase -server $server -status
foreach ($objItem in $db)
{
$lastfull = $objItem.lastfullbackup
if (!$lastfull)
{
$fullago = “n/a”
}
else
{
$fullago = $now – $lastfull
$fullago = $fullago.TotalHours
$fullago = “{0:N0}” -f $fullago
}
$lastinc = $objItem.lastincrementalbackup
if (!$lastinc)
{
$incago = “n/a”
}
else
{
$incago = $now – $lastinc
$incago = $incago.TotalHours
$incago = “{0:N0}” -f $incago
}
$returnedObj = new-object PSObject
$returnedObj | add-member NoteProperty -name “Database” -value $objItem.Name
$returnedObj | add-member NoteProperty -name “Last Full (hrs ago)” -value $fullago
$returnedObj | Add-Member NoteProperty -name “Last Inc (hrs ago)” -value $incago
$returnedObj
}
Write-Host “Press any key to continue …”
$x = $host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”)
Robert, log on to http://www.microsoftvirtualacademy.com/ and enrol/watch the course ‘Getting Started with PowerShell 3.0 Jump Start’. In that you will learn why double-clicking on a .PS1 file won’t work (and why this is actually a GOOD thing!)
You’ll probably have a bit of a laugh here and there too.
PS – It’s free!
Hi Paul
Great script. As I am just learning PowerShell I only get about 70% of the script but it works fine on our Exchange 2007 box so thanks for that. One thing I have been trying is to output the results to a file so the Exchange Team can check the databases are being backed up. I have tried using a pipe to Out-file followed by the path to the text file but I end up with a text file with no data in it if you could possibly advise how to output to a file it would be very much appreciated
Thanks in advance
Simon
You could just send them an automated email with this script:
https://www.practical365.com/set-automated-exchange-2010-database-backup-alert-email/
Thanks Paul
very funky 🙂
Great script! Simplicity is always a key feature!
Pingback: logicspot.NET » Blog Archive