' 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 ' v1.2 Modified to include the count of the number of FOLDERs found ' v1.3 Count the folders in VV rather than the mailbox itself ' CHANGE THE SERVERNAME AND MAILBOX ALIAS BELOW mbxServerName = "EXCH1.EV.LOCAL" mbxName = "CS2" debugmode = 0 set objSession = CreateObject("MAPI.Session") objSession.Logon "", "", false, false, true, true, mbxServerName & vbLF & mbxName ' The second FALSE in the line above means to REUSE the current Outlook session, otherwise we don't see a VV node ' what INFOSTORES do we have in this session? Dim objInfoStoresColl Dim objInfoStore set objInfoStoresColl = objSession.InfoStores if objInfoStoresColl is nothing then wscript.echo "Could not get infostores collection, will now exit" wscript.exit end if if objInfoStoresColl.Count = 0 then wscript.echo "No infostores in the collection, will now exit" wscript.exit end if for x = 1 to ObjInfoStoresColl.Count set objInfoStore = objInfoStoresColl.Item(x) wscript.echo "InfoStore Name : " & objInfoStore.Name & " -- ID : " & objInfoStore.id if instr(objInfoStore.Name, "Vault -") > 0 then ' We found a VV store, that is what we will scan set cdoInfoStore = objInfoStore end if next if cdoInfoStore is nothing then ' We did not find a VV node? wscript.echo "Unable to find a VV node, review the above list. We will now exit" wscript.exit end if 'set cdoInfoStore = objSession.GetInfoStore set cdoFolderRoot = cdoInfoStore.RootFolder ' PerMailbox globals mbxitemcount = 0 mbxfolders = 0 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 mbxfolders = mbxfolders + 1 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 "Number of folders " & mbxfolders wscript.echo "---------------------------------------" wscript.echo "Processing finished at : " & date() & " " & time() wscript.quit sub subAddMessage(msg) mbxitemcount = mbxitemcount + 1 end sub function checkfolder(folder, objsession, d) d = d + 1 set colMessages = folder.Messages if colMessages.Count > 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 mbxfolders = mbxfolders + 1 if debugmode then wscript.echo st & xfolder.Name & " : " & xfolder.Messages.Count end if t = checkfolder(xfolder, objSession, d) next end if end function