One of the things that I need to do on a monthly basis, sometimes on a weekly basis is pull a list of Mailbox stats on our two Exchange Servers. We only have the two servers, and in the grand scheme of things only a small number of users (250 or so spread across both Exchange Servers). The pain on this process is having to go in to each individual Storage Group and then into each Mailbox Store and then export the Mailboxes list to a CSV file.
However this has now changed, I found a simple VBScript on TechRepublic that uses WMI (Windows Management Instrumentation). All you need to do is run this against you Exchange Server and it will gather various statistics on you server: Mailbox name, Size (in kb) the number of items it contains and its status.
I found the status very helpful as you can see whose mailboxes are above or below set limits, and who's mailbox might be restricted or disabled.
These are the 5 Status values:
- Below Limit
- Issue Warning
- Prohibit Send
- No Checking
- Mailbox Disabled
The code I got was from this post:
http://articles.techrepublic.com.com/5100-10878_11-6034303.html#
however I did a little bit of tweaking on it (ok not much) to make it easier to run against multiple servers. In the original script you had to change the server name and the output file name. In my slightly modified version it will prompt you for the server name and output file and then ask you if you want to open the file or not.
'========================================================================
'
' Date: December 23, 2005
' Author: Scott Lowe, starting with a sample script downloaded from
' Microsoft
' Modified: Andrew Kemp, 16th October 2008
' Purpose: Write the name of, size of, number of items in and status
' of each users Exchange mailbox to a CSV file
' Change: cComputerName to the name of an Exchange server
' sOutFile to the name of the file you want to save to
' Output: Displays the name of each Exchange_Mailbox's Size property
' Status: 1: Below Limit
' 2: Issue Warning
' 4: Prohibit Send
' 8: No Checking
' 16: Mailbox Disabled
'
'========================================================================
On Error Resume Next
Dim cComputerName
exchangeserver=inputbox("Please enter the name of the exchange server you want to get the Mailbox Stats for:")
cComputerName = exchangeserver
Const cWMINameSpace = "root/MicrosoftExchangeV2"
Const cWMIInstance = "Exchange_Mailbox"
Dim oFSO ' File system object to write to
Dim oOutputFile ' Output file object
Dim sOutFile ' Name of the output file
outputfile=inputbox("Please enter the file name and path of the out put file eg: C:\exchange_server_name.csv")
sOutFile = outputfile
Dim sWinMgmts ' Connection string for WMI
Dim oWMIExchange ' Exchange Namespace WMI object
Dim lExchange_Mailboxes ' ExchangeLogons collection
Dim oExchange_Mailbox ' A single ExchangeLogon WMI object
' Open the output file for writing
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oOutputFile = oFSO.opentextfile(sOutFile, 2, True)
'Write a heading into the output file
oOutputFile.writeline("Mailbox name,Size (KB),# items,Status")
' Create the object string, indicating WMI (winmgmts), using the
' current user credentials (impersonationLevel=impersonate),
' on the computer specified in the constant cComputerName, and
' using the CIM namespace for the Exchange provider.
sWinMgmts = "winmgmts:{impersonationLevel=impersonate}!//"& _
cComputerName&"/"&cWMINameSpace
Set oWMIExchange = GetObject(sWinMgmts)
' Verify we were able to correctly set the object.
If Err.Number <> 0 Then
oOutputFile.writeline("ERROR: " & err.number & ", " & err.description)
Else
' The Resources that currently exist appear as a list of
' Exchange_Mailbox instances in the Exchange namespace.
Set lExchange_Mailboxes = oWMIExchange.InstancesOf(cWMIInstance)
' Were any Exchange_Mailbox Instances returned?
If (lExchange_Mailboxes.count > 0) Then
' If yes, do the following:
' Iterate through the list of Exchange_Mailbox objects.
For Each oExchange_Mailbox in lExchange_Mailboxes
oOutputFile.writeline("""" & _
oExchange_Mailbox.MailboxDisplayName & _
"""," & _
oExchange_Mailbox.Size & _
","& _
oExchange_Mailbox.TotalItems & _
","& _
oExchange_Mailbox.StorageLimitInfo)
Next
Else
' If no Exchange_Mailbox instances were returned,
' display that.
oOutputFile.writeline("WARNING: No Exchange_Mailbox instances were returned.")
End If
End If
Dim objShell
Set objShell = CreateObject("WScript.Shell")
If MsgBox("Would you like to open the out put file now?", vbYesNo) = vbYes then
objShell.Run("Excel " & outputfile)
End If