March 21, 2011, 3:18 a.m.
posted by sensei
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 & _ "\root\MicrosoftExchangeV2") Set objMbxs = objWMI.ExecQuery("Select * from Exchange_Mailbox",,48) For Each objMbx In objMbxs WScript.Echo objMbx.MailBoxDisplayName & " " & objMbx.size & "KB " _ & objMbx.TotalItems & " items" Next 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.