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. Table 24-4 lists the properties and their descriptions.
Table 24-4. Exchange_Mailbox properties
|
Property |
Description |
|---|---|
|
LegacyDN |
legacyDN of the mailbox. This matches the |
|
MailboxGUID |
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 |