Report the last time your Exchange servers were backed up
Like a lot of my scripts, they start from the hard work that someone else has done. This one began as a similar script that Glen Scales wrote and posted over on his blog. His version enumerates the servers/stores in a domain and outputs the results to the screen.
My needs required some tweaking since I have servers in multiple domains, and I wanted it to email the results to multiple people who are responsible for backups. I also needed to account for servers that don”t have public and/or private stores (e.g., front-end servers, conferencing servers). The script will email the report in HTML format, grouping the stores alphabetically by server name. Change the constants at the top to suit your needs and then schedule it to run daily. My next step is to note stores that haven”t been backed up in X days (perhaps two or three) and highlight them in red so it is easy to spot those stores (since my report currently has 60+ stores in it). Until then, download this version here, or copy it below.
'Change the constants below
CONST strSMTPServer = "Change to server name"
CONST strSMTPRecipient = "Change to recipient address(es)"
CONST strSMTPSender = "Change to sender address"
set conn = createobject("ADODB.Connection")
set mdbobj = createobject("CDOEXM.MailboxStoreDB")
set pdbobj = createobject("CDOEXM.PublicStoreDB")
set com = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("<a href="ldap://RootDSE/">LDAP://RootDSE</a>")
strNameingContext = iAdRootDSE.Get("configurationNamingContext")
Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"
serverQuery = "<GC://" & strNameingContext & ">;(&(objectCategory=msExchExchangeServer));name,distinguishedName;subtree"
Com.ActiveConnection = Conn
Com.Properties("Sort on") = "name"
Com.CommandText = serverQuery
Set Rs = Com.Execute
While Not Rs.EOF
output = output & "<font size=2><u><b>" & Rs.Fields("name") & "</b></u></font>" & vbcrlf
mbQuery = "<LDAP://" & strNameingContext & ">;(&(objectCategory=msExchPrivateMDB)(legacyExchangeDN=*" & _
Rs.Fields("name") & "/cn=Microsoft Private MDB));name,distinguishedName;subtree"
pfQuery = "<LDAP://" & strNameingContext & ">;(&(objectCategory=msExchPublicMDB)(legacyExchangeDN=*" & _
Rs.Fields("name") & "/cn=Microsoft Public MDB));name,distinguishedName;subtree"
Com.CommandText = mbQuery
Set Rs1 = Com.Execute
If Rs1.RecordCount = 0 Then
output = output & "<table><tr><td width=50%><font size=2> No mailbox stores." & _
"</font></td></tr>" & vbcrlf
Else
output = output & "<table>"
While Not Rs1.EOF
mdbobj.datasource.open "LDAP://" & Rs1.Fields("distinguishedName")
output = output & "<tr><td width=50%><font size=2> " & Rs1.Fields("name") & _
" </font></td><td><font size=2>Last Backed Up :" & mdbobj.LastFullBackupTime & "</font></td></tr>" & vbcrlf
Rs1.MoveNext
Wend
End If
Rs1.Close
Com.CommandText = pfQuery
Set Rs2 = Com.Execute
If Rs2.RecordCount = 0 Then
output = output & "<tr><td width=50%><font size=2> No public folder store.</td></tr>" & vbcrlf
Else
pdbobj.datasource.open "LDAP://" & Rs2.Fields("distinguishedName")
output = output & "<tr><td width=50%><font size=2> " & _
Rs2.Fields("name") & " </font></td><td><font size=2>Last Backed Up :" & _
pdbobj.LastFullBackupTime & "</font></td></tr>" & vbcrlf
End If
output = output & "</table>"
Rs2.Close
On Error Goto 0
output = output & vbcrlf
Rs.MoveNext
Wend
Set iMsg = CreateObject("CDO.Message")
With iMsg
.To = strSMTPRecipient
.From = strSMTPSender
.Subject = "Last Exchange Backup Report"
.HTMLBody =Â output
.Configuration.Fields.Item("<a href="http://schemas.microsoft.com/cdo/configuration/sendusing">http://schemas.microsoft.com/cdo/configuration/sendusing</a>") = 2
.Configuration.Fields.Item("<a href="http://schemas.microsoft.com/cdo/configuration/smtpserver">http://schemas.microsoft.com/cdo/configuration/smtpserver</a>") = strSMTPServer
.Configuration.Fields.Item("<a href="http://schemas.microsoft.com/cdo/configuration/smtpserverport">http://schemas.microsoft.com/cdo/configuration/smtpserverport</a>") = 25
.Configuration.Fields.Update
.Send
End With
Rs.Close
Conn.Close
set mdbobj = Nothing
set pdbobj = Nothing
Set Rs = Nothing
Set Rs1 = Nothing
Set Rs2 = Nothing
Set Com = Nothing
Set Conn = Nothing

