• Facebook
  • RSS Feed
  • Instagram
  • LinkedIn
  • Twitter
Nov 032010
 

I wrote this simple vbscript + CDO combination to scan through a mailbox, and show the folder structure, and count the number of items in each folder:

servername="EXCH1"
mailboxname="DOG2"

Set objSession = CreateObject("MAPI.Session")
objSession.Logon "","",false,true,true,true,servername & vbLF & mailboxname
Set CdoInfoStore = objSession.GetInfoStore
Set CdoFolderRoot = CdoInfoStore.RootFolder
numcharstoindent=1

‘ Start at the very top of the information store
set oFolders = cdoFolderRoot.folders
if ofolders.count > 0 then
    wscript.echo "Mailbox : " & mailboxname

    for each ofolder in oFolders
        t = checkmsgsinfolder(ofolder, objSession)
    next
else
    wscript.echo "No folders to process"
end if

wscript.quit

function checkmsgsinfolder(folder, objsession)

    s= ""
    for i = 1 to numcharstoindent   
    s = s & " "
    next
    wscript.echo s & folder.name & " : " & folder.messages.count

    numcharstoindent=numcharstoindent+2
    for each mfolder in folder.folders
        x = checkmsgsinfolder(mfolder, objsession)
    next
    numcharstoindent=numcharstoindent-2

end function

 

 

The output looks like this :

C:>cscript try2.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Mailbox : DOG2
1 : 0
1r : 0
Calendar : 0
Contacts : 0
Conversation Action Settings : 0
Deleted Items : 0
Drafts : 0
Inbox : 12
   t1 : 0
     dingo123 : 0
   t2 : 1
   x123 : 0
Journal : 0
Junk E-mail : 22
News Feed : 0
Notes : 0
Outbox : 0
Quick Step Settings : 0
RSS Feeds : 0
Sent Items : 14
Suggested Contacts : 0
Sync Issues : 0
   Conflicts : 0
   Local Failures : 0
   Server Failures : 0
Tasks : 0

Each subfolder is indented by a space, so you get a nice on-screen layout.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)