HOWTO: Get Exchange 2000/2003 mailbox statistics remotely using WMI

Of course you cannot use WMI to manage Exchange 2007, obviously Powershell is more power full and recommended to be used on Exchange 2007 Server.

We will talk about Powershell and how to do same for 2007 later. For now you can use following script to get the statistics data from Exchange WMI Provider and Exchange_Mailbox class of it.

 

 On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("Server1", "Server2", "Server3")

For Each strComputer In arrComputers
    WScript.Echo
    WScript.Echo "=========================================="
    WScript.Echo "Exchange Server: " & strComputer
    WScript.Echo "=========================================="

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftExchangeV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Exchange_Mailbox", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

    For Each objItem In colItems
        WScript.Echo "AssocContentCount: " & objItem.AssocContentCount
        WScript.Echo "Caption: " & objItem.Caption
        WScript.Echo "DateDiscoveredAbsentInDS: " & WMIDateStringToDate(objItem.DateDiscoveredAbsentInDS)
        WScript.Echo "DeletedMessageSizeExtended: " & objItem.DeletedMessageSizeExtended
        WScript.Echo "Description: " & objItem.Description
        WScript.Echo "InstallDate: " & WMIDateStringToDate(objItem.InstallDate)
        WScript.Echo "LastLoggedOnUserAccount: " & objItem.LastLoggedOnUserAccount
        WScript.Echo "LastLogoffTime: " & WMIDateStringToDate(objItem.LastLogoffTime)
        WScript.Echo "LastLogonTime: " & WMIDateStringToDate(objItem.LastLogonTime)
        WScript.Echo "LegacyDN: " & objItem.LegacyDN
        WScript.Echo "MailboxDisplayName: " & objItem.MailboxDisplayName
        WScript.Echo "MailboxGUID: " & objItem.MailboxGUID
        WScript.Echo "Name: " & objItem.Name
        WScript.Echo "ServerName: " & objItem.ServerName
        WScript.Echo "Size: " & objItem.Size
        WScript.Echo "Status: " & objItem.Status
        WScript.Echo "StorageGroupName: " & objItem.StorageGroupName
        WScript.Echo "StorageLimitInfo: " & objItem.StorageLimitInfo
        WScript.Echo "StoreName: " & objItem.StoreName
        WScript.Echo "TotalItems: " & objItem.TotalItems
        WScript.Echo
    Next
Next


Function WMIDateStringToDate(dtmDate)

    WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _ 
            Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) & " " & _  
            Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
End Function

Feel free to ping me if you do not understand anything or need some help.