Link to home
Start Free TrialLog in
Avatar of subversive99
subversive99

asked on

Need script to count messages in all outlook folders

Hi, we are doing a large scale mail migration from Scalix to online Exchange. I am running a migration tool which is workign well, however I need to verify that all mail was migrated in each users case. However, this is extremely tedious as many of the users have extremely deep folder structures inside of outlook and clicking through each one is not realistic.

What I would like is a script which can scan a local outlook profile (I have credentials for each user and can create a local mail profile for each one), and pull a list of folders, and the number of messages in each folder into Excel. From this, I will be able to compare with my migration results to ensure the number of messages match up. If there are cases where messages were missed, it will be easy for me to see and dig deeper.

I'm also not very well versed in scripting, so if you could include instructions on how exactly I would run the script, this would be appreciated.

If you need any further information, please let me know.

Thanks.
Avatar of hitsdoshi1
hitsdoshi1

There you go...
Set olApp = CreateObject("Outlook.Application")
Set olns = olApp.GetNameSpace("MAPI")
    For icnt = 1 To olns.Folders.Count
            Set Folder = olns.Folders.Item(icnt)
            msgbox Folder.Items.Count
    Next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of JonMny
JonMny

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of subversive99

ASKER

Hi Jonmny, thanks this looks promising. Can you give me a quick walk through on how to run it?

Also, does there need to be only one outlook profile on the system, or will this allow me to select which profile to scan? Thanks.
Works like a charm, thanks!
this is just a vbscript file, if you copy to a textfile and give it the extension of .vbs it will run.

you will want to change line 8 to a valid path for  your system

Set filetxt = filesys.CreateTextFile("f:\outlook.csv", True)

I only have one profile on my machine so I cant test this but If you use the modified code below It should use the selected profile


Dim olns
Set olApp = CreateObject("Outlook.Application")
Set olns = olApp.GetNameSpace("MAPI")
profile=inputbox ("Input Profile" )
olns.Logon profile
dim filesys, filetxt, getname, path 
Set filesys = CreateObject("Scripting.FileSystemObject") 
Set filetxt = filesys.CreateTextFile("f:\outlook.csv", True) 
folderinfo(olns.folders)
filetxt.Close 
msgbox "finished"
Function  folderinfo(folders)
for each folder in folders    
filetxt.WriteLine("Folder '" & Folder.Name & "," &  Folder.Items.Count &  "," & folder.parent )

	folderinfo(folder.folders)
    Next
   
   
End Function

Open in new window