Exchange 2003 Mailbox Size

This script is used to get mailbox item size in Exchange for users by their OU rather than their mailbox server.  Copy the script below into a text editor and save the output as a VBS file.  The items in red need to be adjusted to fit your environment.

For more information, see our blog post for this script.

Copy the content from the box below or download E2K3_Mailbox_Size_By_OU.txt (4.62 kb) in TXT format.  After downloading, rename the script to E2K3_Mailbox_Size_By_OU.vbs.

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"

Happy Exchanging!!!

Powered by BlogEngine.NET 1.5.0.7 | Log in

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar