' Script by Rob Wilcox, 10th May 2011 ' ' Process a mailbox, and count the number of items in each folder, the size etc, recursively down the whole folder tree. ' ' v1.0 ' v2.0 - Modified to output summary of all message classes - 26th March 2012 ' CHANGE THE SERVERNAME AND MAILBOX ALIAS BELOW mbxServerName = "EXCH1.EV.LOCAL" mbxName = "jeff1" set objSession = CreateObject("MAPI.Session") objSession.Logon "", "", false, true, true, true, mbxServerName & vbLF & mbxName set cdoInfoStore = objSession.GetInfoStore set cdoFolderRoot = cdoInfoStore.RootFolder ' PerMailbox globals mbxitemcount = 0 mbxsize = 0 mbxarchsize = 0 mbxpendingsize = 0 mbxarchcount = 0 mbxpendingcount = 0 dim mbxmsgclass_array(100,3) mbxmsgclass_array_i = 1 wscript.echo "Processing started at : " & date() & " " & time() wscript.echo "Scanning mailbox : " & mbxName wscript.echo "-------------------------------------" set oFolders = cdoFolderRoot.Folders ' Process TOIS first set colMessages = cdoFolderROot.Messages if colMessages.Count > 0 then for each oMessage in colMessages call subAddMessage(oMessage) next end if wscript.echo cdoFolderRoot.Name & " : " & cdoFolderRoot.Messages.Count ' Now process subfolders if ofolders.count > 0 then for each ofolder in ofolders wscript.echo " " & ofolder.Name & " : " & ofolder.messages.Count t = checkfolder(ofolder, objSession, 1) next end if ' Eventual summary wscript.echo "---------------------------------------" wscript.echo "Number of items in the mailbox : " & mbxItemCount wscript.echo "Total size : " & mbxsize & " Bytes, " & round(mbxsize/1024,2) & " Kbytes, " & round(mbxsize/1024/1024, 2) & " Mb" wscript.echo "Number of archived items : " & mbxarchcount wscript.echo "Archived items size : " & mbxarchsize & " Bytes, " & round(mbxarchsize/1024,2) & " Kbytes, " & round(mbxarchsize/1024/1024,2) & " Mb" wscript.echo "Number of pending items : " & mbxpendingcount wscript.echo "Pending items size : " & mbxpendingsize & " Byes, " & round(mbxpendingsize/1024, 2) & " Kbytes, " & round(mbxpendingsize/1024/1024,2) & " Mb" wscript.echo "---------------------------------------" wscript.echo "" wscript.echo "Summary by Message Class:" wscript.echo "" for i = 1 to mbxmsgclass_array_i - 1 wscript.echo mbxmsgclass_array(i,1) & " - " & mbxmsgclass_array(i,2) & " - Size: " & mbxmsgclass_array(i,3) & " bytes, " & round(mbxmsgclass_array(i,3)/1024/1024,2) & " Mb" next wscript.echo "" wscript.echo "Processing finished at : " & date() & " " & time() wscript.quit sub subAddMessage(msg) mbxitemcount = mbxitemcount + 1 mbxsize = mbxsize + msg.size if msg.type = "IPM.Note.EnterpriseVault.Shortcut" then mbxarchsize = mbxarchsize + msg.size mbxarchcount = mbxarchcount + 1 end if if instr(msg.type, "Pending") then mbxpendingsize = mbxpendingsize + msg.size mbxpendingcount = mbxpendingcount + 1 end if call add_to_array(msg) end sub sub add_to_array(msg) ' Check if in the array already found = false i = 1 msgclassname = ucase(msg.type) while found = false and i 0 then for each oMessage in colMessages call subAddMessage(oMessage) next end if if folder.folders.count > 0 then st = "" for i = 1 to d st = st + " " next for each xfolder in folder.folders wscript.echo st & xfolder.Name & " : " & xfolder.Messages.Count t = checkfolder(xfolder, objSession, d) next end if end function