VBScript to read Exchange 2003 mailbox store total size

In Exchange 2007, you have PowerShell to perform powerful queries on mailbox stores, which make it easy to get the total size of a mailbox store by calculating all mailbox contents in bytes. In Exchange 2003 however, you need to do this with WMI which doesn’t know about mailbox stores but only allows you to query mailboxes.

The script below does 2 loops through all mailboxes. The first one is to get a unique list of all the mailbox stores from each mailbox, and the second one is to calculate the total size of each unique mailbox store from all the mailboxes. In my tests it takes about 30 seconds for an environment of 3 mailbox stores with over 9000 mailboxes.
The script takes 2 parameters, Exchange server and output file. The output file will contain the following data:
mailbox store 1|5262342
mailbox store 2|23489
mailbox store 3|60930235
dim fso, StoreArray, StoreName_cache
set fso = CreateObject(“Scripting.FileSystemObject”)
strComputerName = wscript.arguments(0)
strOutput = wscript.arguments(1)
set output = fso.CreateTextFile(strOutput, True)
strE2K3WMIQuery = “winmgmts://” & strComputerName & “/root/MicrosoftExchangeV2”
Set mboxList = GetObject(strE2K3WMIQuery).InstancesOf(“Exchange_Mailbox”)
StoreName_cache = “”
For each mailbox in mboxList
if InStr(StoreName_cache, mailbox.StoreName) = 0 then
StoreName_cache = StoreName_cache & “;” & mailbox.StoreName & “|0”
end if
StoreName_cache = Mid(StoreName_cache, 2, Len(StoreName_cache))
StoreArray = Split(StoreName_cache, “;”)
For each mailbox in mboxList
For currentIndex = 0 to UBound(StoreArray)
tmpArray = Split(StoreArray(currentIndex), “|”)
if tmpArray(0) = mailbox.StoreName then
tmpSize = CLng(tmpArray(1)) + CLng(mailbox.Size)
StoreArray(currentIndex) = mailbox.StoreName & “|” & tmpSize
end if
For currentIndex = 0 to UBound(StoreArray)
output.WriteLine StoreArray(currentIndex)

Geschreven door:

Arnout van der Vorst

Arnout van der Vorst is Identity Management Architect bij Tools4ever en al ruim 10 jaar in dienst. Arnout legt zich als Architect toe op het bedenken en ontwikkelen van nieuwe features, oplossingen en diensten van Tools4ever die aansluiten op de vraag uit de markt. Arnout studeerde Hogere Informatica aan de Hogeschool van Utrecht.