Viewing Mailbox Sizes and Message Counts

Viewing Mailbox Sizes and Message Counts

A common task is to look at an Exchange server and determine the sizes and counts of messages on the server for all mailboxes. The following code shows how simple this is to do:

    ' This code enumerates mailbox sizes and message counts.
    Option Explicit
    Dim strComputer, objWMI, objMbxs, objMbx
    ' ------ SCRIPT CONFIGURATION ------
    strComputer = "<Exchange Server>" 'e.g. ExchServer2
    ' ------ END CONFIGURATION ---------

    Set objWMI = GetObject("winmgmts:\\" & strComputer & _
    Set objMbxs = objWMI.ExecQuery("Select * from Exchange_Mailbox",,48)
    For Each objMbx In objMbxs
      WScript.Echo objMbx.MailBoxDisplayName & " " & objMbx.size & "KB  " _
                   & objMbx.TotalItems & " items"
    WScript.Echo "Script completed successfully."

This script is very similar to the script to enumerate disconnected mailboxes. The same basic process is used; we have simply changed the initial query to select the record set to enumerate through. There are actually several properties that can be displayed this way. Figure lists the properties and their descriptions.

Exchange_Mailbox properties




legacyDN of the mailbox. This matches the legacyExchangeDN attribute of the user object in Active Directory.


Indicates the globally unique identifier (GUID) that links the mailbox to a user in Active Directory. This value is also populated in the user's Active Directory object as msExchMailboxGuid.


Name of the server the mailbox resides on.


Indicates the name of the storage group that contains the mailbox.


Indicates the name of the message database (MDB) that contains the mailbox.


Indicates the total number of messages associated with the mailbox folders.


Indicates when the store detected that the mailbox no longer had a corresponding user entry in Active Directory; i.e., when the mailbox was disconnected.


Indicates the cumulative size of all deleted messages that are still being retained according to retention policy settings.


Indicates the account name last used to log onto the mailbox. Note that this doesn't necessarily mean an interactive logon to the mailbox messages; this could be from someone viewing a calendar entry or other innocuous access.


Indicates the time that the last user logged off. See note for LastLoggedOnUserAccount.


Indicates the time that the last user logged on. See note for LastLoggedOnUserAccount.


Indicates cumulative size of all of the messages in the mailbox in bytes.


Contains the storage limit settings on the mailbox.


Indicates the total number of messages in a mailbox.

 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows