PowerShell Script: Check Exchange Mailbox Database Last Backup Time

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
}
About Paul Cunningham

Paul is a Microsoft Exchange Server MVP and publisher of Exchange Server Pro. He also holds several Microsoft certifications including for Exchange Server 2007, 2010 and 2013. Connect with Paul on Twitter and Google+.

Comments

  1. Great script! Simplicity is always a key feature!

Leave a Comment

*

We are an Authorized DigiCert™ SSL Partner.
Loading...

Still running Exchange 2003? Time to get moving and start your upgrade. Find out how - Click Here