Did you ever want to get mailbox item size in Exchange 2003 based off users in a specific OU and not based off the mailbox server the users reside on? If so you’re in luck :). What I have done is add some code in a VBScript that will gather all the users in an OU and compare those users against a list of mailbox servers that are specified in the script. Most of the script’s content was taken from this site: http://www.computerhope.com/htmcolor.htm . Since the script is comparing users’ accounts in an OU against mailboxes on a mailbox server, the process could take some time to run. To give you an idea, I have a 1,000 users and mailboxes in my test lab and the script took about 3 minutes to run.  As with any script that you get from our site or any other site please test in a development lab and not against your production environment. I have seen many of customers run into a lot of problems when they run scripts downloaded from the Internet. I will try to improve the script over time.

You can get the script right here .

Option Explicit
'On Error Resume Next
Dim ServerList                  ' List of computers to check
Dim server                                          ' Current computer to check
Dim fso                                                                ' File System Object
Dim strWinMgmts                                           ' Connection string for WMI
Dim objWMIExchange                   ' Exchange Namespace WMI object
Dim listExchange_Mailboxs        ' ExchangeLogons collection
Dim objExchange_Mailbox                          ' A single ExchangeLogon WMI object
Dim logfile                                         ' Output file

Dim ou1

Dim provider

Dim objParent

Dim WshShell

Dim objUser

'Set objParent = GetObject(provider & ou1)

ou1 = "OU=Users ,DC=domain,DC=com"

provider = "LDAP://"

Const cWMINameSpace = "root/MicrosoftExchangeV2"

Const cWMIInstance = "Exchange_Mailbox"

Const LOG_FILE = "EMailSize.csv"

set objParent = GetObject(provider & ou1)

objParent.Filter = Array("user")

'--------------------------------------

' Set up the email servers

'--------------------------------------

ServerList  = Array("mailbox1", "mailbox2")

'--------------------------------------

' Set up log file

'--------------------------------------

set fso = CreateObject("Scripting.FileSystemObject")

Set logfile = fso.CreateTextFile(LOG_FILE)

logfile.WriteLine("""Display Name"",""Mailbox Size"",""Mailbox TotalItems"",""Mailbox StoreName"",""Mailbox ServerName""")

' Create the object string, indicating WMI (winmgmts), using the

' current user credentials (impersonationLevel=impersonate),

' on the computer specified in the constant cComputerName, and

' using the CIM namespace for the Exchange provider.

WScript.Echo "Starting now"

'The rest of the script will fetch mailbox sizes for our servers. Mailbox sizes are in Kilobytes.

For Each server in ServerList

                WScript.Echo "Starting " & server & " search."

                strWinMgmts = "winmgmts:{impersonationLevel=impersonate}!//" & server & "/" & cWMINameSpace

                'WScript.Echo strWinMgmts

                Set objWMIExchange =  GetObject(strWinMgmts)

                ' Verify we were able to correctly set the object.

                If Err.Number <> 0 Then

                                WScript.Echo "ERROR: Unable to connect to the WMI namespace."

                Else

                                'The Resources that currently exist appear as a list of

                                'Exchange_Mailbox instances in the Exchange namespace.

                                Set listExchange_Mailboxs = objWMIExchange.InstancesOf(cWMIInstance)

                                ' Were any Exchange_Mailbox Instances returned?

                                If (listExchange_Mailboxs.count > 0) Then

                                                ' If yes, do the following:

                                               ' Iterate through the list of Exchange_Mailbox objects.

                                                For each objUser in objParent

                                                                For Each objExchange_Mailbox in listExchange_Mailboxs

                                                                'WScript.Echo objUser.displayname & objExchange_Mailbox.MailboxDisplayName

                                                                                If objUser.displayname = objExchange_Mailbox.MailboxDisplayName then

                                                                                ' Display the value of the Size property.

                                                                                logfile.WriteLine("""" & objExchange_Mailbox.MailboxDisplayName & """,""" & objExchange_Mailbox.Size & """,""" & objExchange_Mailbox.TotalItems & """,""" & objExchange_Mailbox.StoreName & """,""" & objExchange_Mailbox.ServerName & """")

                                                                                End If

                                                                Next

                                                Next

                                Else

                                                ' If no Exchange_Mailbox instances were returned, display that.

                                                WScript.Echo "WARNING: No Exchange_Mailbox instances were returned."

                                End If

                End If

Next

Wscript.Echo "Completed"