This script uses WMI and Active Directory queries to return information about mailbox sizes from Exchange and the limits set in Active Directory.

Download GetMailboxStatistics.vbs

A number of people have been looking for Get-MailboxStatistics for Exchange 2003. I have a PowerShell version of this script for exactly that reason here.

This script is only intended for use with Exchange 2003. Exchange 2000 must use MAPI, Exchange 2007 has a PowerShell cmdlet, Get-MailboxStatistics, which can much more easily return this information.

It requires access to WMI on each Exchange Server, but does not require any of the Exchange System Tools. legacyExchangeDN is used to match accounts between AD and Exchange.

The script performs a number of searches in Active Directory. The largest number if multiple Admin Groups are selected (/a:”Admin Group*”). It can be instructed to use a single DC by specifying a name with the /dc switch. For forest-wide searches that must be a Global Catalog. If no DC is specified the script executes a DNS query for Global Catalog service records on the current forest name to attempt to find a (responding) GC in the current site, failing back to any GC in the forest otherwise.

Usage

[code lang=”plain”]
cscript GetMailboxStatistics.vbs [/o] [/s:]
[/a:”“] [/d:]
[/dc:] [/f:]

One of the following parameters must be specified:

/o Get statistics from all Exchange Servers in the organisation
This option overrides all others
/s Get statistics for this Exchange Server only
This option overrides all except /o
/a Get statistics from all Exchange Servers in the specified Administrative Group
/d Get statistics from all Exchange Servers in the specified Domain

The following parameters are optional:

/dc A Domain Controller to use for this process. Must be a Global Catalog
for reporting that covers a Forest. The script will attempt to find a
GC in the current site if not specified.
/f File Name for the output. Default file name is MailboxReport.csv

The following details are returned by this script:

  • Name
  • DN
  • AccountStatus (Enabled / Disabled)
  • UseDefaultQuotas (True / False)
  • Warn (in Mb, Warning Limit if specified on User Account)
  • ProhibitSend (in Mb, if specified on User Account)
  • ProhibitSendAndReceive (in Mb, if specified on User Account)
  • Size (in Mb)
  • TotalItems
  • MailboxStatus (BelowLimit, IssueWarning, ProhibitSend, NoChecking, MailboxDisabled)
  • AssocContentCount (Total Number of messages associated with the mailbox folders)
  • DeletedMessageSize (in Mb)
  • LastLoggedOnUser
  • LastLogon
  • LastLogoff
  • DateDeleted (for mailboxes which have been disconnected, waiting to be purged)
  • MailboxDisplayName
  • MailboxGuid
  • ServerName (Exchange Server)
  • StorageGroup
  • Store
  • legacyExchangeDN

17 Comments

  1. Modified, to show LastLogon info instead of StoreLimits.

    Code snipped. Main script has been updated to include LastLogon and all other interesting WMI attributes. Chris

    Reply

  2. Edited to add code-formatting / remove HTML tags, thanks Zygi 🙂

    Chris

    Reply

  3. Hi, when i run this i get the error

    D:E2K3 SG SizeGetStoreLimits.vbs(21, 60) Microsoft VBScript compilation error:
    Expected ‘)’

    i presume i am doing something very silly

    Reply

  4. Nope, not you. It looks like the code isn’t displaying properly after I updated the code formatting plug-in. I’ve changed it to a text attachment which should work better.

    Chris

    Reply

  5. Hi there,

    Got the script and wanted to test it on my exchange server – I see I need the exchange system tools. Does anyone have a download link to these? From what I can see MS doesn’t offer this as a complete packaged download anymore, only individual downloads for each tool…

    Reply

  6. Ok so I copy-pasted your code into textpad, saved as mailboxes.vbs double-clicked, but it gives an error on line 137, character 51. Expected “)”

    Any ideas? Do I need to run it from a specific location?

    Reply

  7. The version from the linked text file at the top? Can’t reproduce the error with that one.

    Chris

    Reply

  8. Hi there,
    I ran into a problem running the script. Am I doing something wrong? When I run the following:

    cscript getmailboxstatistics.vbs /s:exchange1

    It returns this error:

    getmailboxstatistics.vbs(168, 5) Microsoft VBScript runtime error: This key is already associated with an element of this collection

    thanks for your help!
    Matt

    Reply

  9. If you’re supplying a server name it should only be looking for users, which suggests that you have a user with a duplicate LegacyExchangeDN (because that’s the Key).

    On the line above 168, add “WScript.Echo strKey”, then it’ll echo out every key it’s trying to store.

    Chris

    Reply

  10. Hi Chris,

    Your script is perfect for what I’m after, however when I run it in my environment it only reports back the AD attributes for 83 out of 960 users on one of my servers. The WMI results are all present and correct and I’ve checked the script to see if anything looks out of place. I’m running as a domain admin so there should be no problem with my access rights to these objects.

    Marcus

    Reply

    • It fails on all AD attributes? It’s doing a case-insensitive comparison of the legacyExchangeDN value, it’s possible those might be different although they really shouldn’t be.

      Chris

      Reply

  11. Hi Chris,

    Thanks for the response and sorry for the delay posting back. I confirmed that the legacyexchangeDN attribute was correct on both sides and then used wireshark to analyse the process when the script makes it’s LDAP calls, the issue is the 1000 record default limit to LDAP lookups. When the script queries (&(objectClass=user)(objectCategory=person)(legacyExchangeDN=*)) it baulks after 1000 records and I’ve got 11,500 mailboxes on my system.

    I’ll temporarily change then LDAP policy to allow it to run this time.

    Marcus

    Reply

  12. Great script thanks.

    Reply

  13. Chris,

    This is great! What effort would it take to add folder listing and item count per folder to the output?

    Thank you,

    Chris G.

    Reply

  14. thank you so much, I will continue to use PFDAVAdmin to pull the folder item count. Thank you again for all your help!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *