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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
'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>&nbsp;&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;&nbsp;" & 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>&nbsp;&nbsp;&nbsp;&nbsp;No public folder store.</td></tr>" & vbcrlf Else pdbobj.datasource.open "LDAP://" & Rs2.Fields("distinguishedName") output = output & "<tr><td width=50%><font size=2>&nbsp;&nbsp;&nbsp;&nbsp;" & _ 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 |
Dear Scott, Thank you for the Script.
I tried it out but it does not work.
it does not come up with any output neither it does send an email address.
could you please help me run the script.
Regards