27
Jul/09
1

How to Check Mailbox Size on Exchange Server via Script

Here’s a small VBScript that enumerates an Exchange Information Store and lists all Mailbox sizes.
Takes 1 Argument (ExchangeServerName)

Run “cscript MSX_GetMailboxSize.vbs YOUREXCHANGESERVER>Output.csv” to get a Comma Separated Value file.

VBScript Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
On Error Resume Next
Dim cComputerName
Const cWMINameSpace = "root/MicrosoftExchangeV2"
Const cWMIInstance = "Exchange_Mailbox"
cComputerName = WScript.Arguments(0)
 
Dim strWinMgmts
Dim objWMIExchange
Dim listExchange_Mailboxs
Dim objExchange_Mailbox	
 
strWinMgmts = "winmgmts:{impersonationLevel=impersonate}!//"& _
cComputerName&"/"&cWMINameSpace
Set objWMIExchange =  GetObject(strWinMgmts)
 
If Err.Number <> 0 Then
  WScript.Echo "ERROR: Unable to connect to the WMI namespace."
Else
 
  Set listExchange_Mailboxs = objWMIExchange.InstancesOf(cWMIInstance)
 
  If (listExchange_Mailboxs.count > 0) Then
 
    WScript.Echo "Display Name,SizeMB,SizeGB,Storage Group,Store,Total Items"
    For Each objExchange_Mailbox in listExchange_Mailboxs
       WScript.Echo objExchange_Mailbox.MailboxDisplayName & "," & Round(FormatNumber(objExchange_Mailbox.Size / 1024, 2), 0) & "," & Round(FormatNumber(objExchange_Mailbox.Size / 1024 / 1024, 2), 2) & "," & objExchange_Mailbox.StorageGroupName & "," & objExchange_Mailbox.StoreName & "," & objExchange_Mailbox.TotalItems
    Next
  Else
    WScript.Echo "WARNING: No Exchange_Mailbox instances were returned."
  End If
End If
Print This Post
(5 votes, average: 3.20 out of 5)
Loading ... Loading ...
2,370 views