Sunday, September 5, 2010

Generate a report of the "Last Full Backup Time" for all Exchange 2003 Mailbox Stores across the Enterprise

Friday, July 10, 2009, 10:38
This news item was posted in Active Directory, Exchange 2003, Scripting category and has 0 Comments so far.

Managing a large and distributed Exchange 2003 environment can be a challenging task for administrators, specifically when it comes to staying on top of critical maintenance – like ensuring that all your Exchange servers are being routinely backed up. Using the Exchange System Manager to check the status of each Mailbox Store for every Exchange server in a large environment quickly becomes a time consuming and tedious task that is prone to providing inaccurate results. Hopefully we all have competent Administrators who are local to the Exchange servers in our organization that we can rely on to ensure that each server is being managed appropriately, and monitoring tools like System Center Operations Manager that can help keep us informed of the health of every server. Unfortunately the reality is that we don't always have the luxury of powerful monitoring tools or competent staff and there are times when we need to farm information to quickly get a snapshot of the health of the organization. To help with this need, we have created a quick and easy solution for Exchange administrators to painlessly gather this data. We accomplish this task by executing two different .vbs scripts to produce a text file that contains the name of every Mailbox Store in the entire forest along with the Date and Time that the last Full Backup was performed.

The first script will walk the entire Active Directory Forest and gather the distinguished name of every Exchange 2003 Mailbox Store, which we will need in order to query the LastFullBackupTime value. Copy the contents of this script into a new text document named "GetMailBoxStoreDN.vbs".

Set objRootDSE = GetObject("LDAP://RootDSE")
configurationNamingContext = objRootDSE.get("configurationNamingContext")

Set cn = CreateObject("ADODB.Connection")
Set cmd = CreateObject("ADODB.Command")
Set rs = CreateObject("ADODB.Recordset")

cn.Open "Provider=ADsDSOObject;"

query = "<LDAP://" & configurationNamingContext & ">;(objectCategory=msExchPrivateMDB);name,cn,distinguishedName;subtree"

cmd.ActiveConnection = cn
cmd.CommandText = query
Set rs = cmd.Execute

While rs.EOF <> True And rs.BOF <> True
wscript.echo rs.Fields("distinguishedname").Value
rs.MoveNext
Wend

Set rs = Nothing
Set cmd = Nothing
Set cn = Nothing

Now that we have the first script ready, you'll need to execute it by opening up a command prompt and navigating to the location where the script resides. Type "cscript GetMailBoxStoreDN.vbs > MailBoxStoreDN.txt" to execute the script and pipe the results to a text file which will be used in the next step to query for the LastFullBackupTime value.

Once the first script has completed we'll need to use the 2nd script to gather the LastFullBackupTime value. Before we do so, you'll need to edit the resulting txt file from the first script and remove the first few lines at the top so the file only contains the distinguishedName of each Mailbox Store. Copy the contents of the script below into a new text document named "GetLastFullBackupTime.vbs". This script will loop through the contents of the MailBoxStoreDN.txt file and query the LastFullBackupTime value from each Mailbox Store. You'll need to execute this script in a similar fashion, by opening a command prompt and navigating to the location of the MailBoxStoreDN.txt and GetLastFullBackupTime.vbs. Type "cscript GetLastFullBackupTime.vbs > LastFullBackupTime.txt" to execute the script and pipe the results to a text file.

Option Explicit
On Error Resume Next
Dim oFSO, sFile, oFile, sText, mdbobj
Set oFSO = CreateObject("Scripting.FileSystemObject")
set mdbobj = createobject("CDOEXM.MailboxStoreDB")
sFile = "MailBoxStoreDN.txt"
If oFSO.FileExists(sFile) Then
Set oFile = oFSO.OpenTextFile(sFile, 1)
Do While Not oFile.AtEndOfStream
sText = oFile.ReadLine
If Trim(sText) <> "" Then
mdbobj.datasource.open "LDAP://" & sText
Wscript.echo "Mailbox Store:," & sText & ",Last Backed Up : " & mdbobj.LastFullBackupTime
End If
Loop
oFile.Close
Else
WScript.Echo "The file was not there."
End If

Once the script has completed running,  open the LastFullBackupTime.txt file to view the results, or copy the contents into Excel if you prefer to make use of the text-to-columns and sorting features for better readability. While we admit this solution lacks elegance and requires a small bit of intervention from start to finish, this method is very effective for quickly determining the status of backups against Exchange for the entire enterprise and can easily be modified to query for the Last Incremental Time as well if necessary.

You can leave a response, or trackback from your own site.

Leave a Reply