Hello everyone,
I found and online script that retrieves mailboxes larger than 400MB and list those mailboxes as a csv file. I would like to edit this script to retrieve and list mailboxes according to size via each mailbox store. This curent script, though helpful, retrieves mailboxes from all the mailbox stores on the Exchange server I need a granular search via mailbox stores. Any help will be appreciated.
Option Explicit
On Error Resume Next
Dim ServerList 'List of Computers to check
Dim server ' Current computer to check
Dim fso ' File System Object
Dim strWinMgmts ' Connection string for WMI
Dim objWMIExchange ' Exchange Namespace WMI object
Dim listExchange_Mailboxes ' Exchange_Mailbox collection
Dim objExchange_Mailbox ' A single Exchange_Mailbox WMI object
Dim logfile ' Output file
Const cWMINameSpace = "root/MicrosoftExchangeV2"
Const cWMIInstance = "Exchange_Mailbox"
Const LOG_FILE = "Mailbox size.csv"
'List the Exchange servers
ServerList = Array("SERVER1", "SERVER2")
'Create the log file and display parameters
set fso = CreateObject("Scripting.FileSystemObject")
Set logfile = fso.CreateTextFile(LOG_FILE)
logfile.WriteLine("""Display Name"",""Mailbox Size"",""Mailbox StoreName"",""Mailbox
ServerName""")
' Create the object string, indicating WMI (winmgmts), using the
' current user credentials (impersonationLevel=impersonate),
' on the computer specified in the constant server, and
' using the CIM namespace for the Exchange provider.
WScript.Echo "Starting now"
For Each server in ServerList
WScript.Echo "Starting " & server & " search."
strWinMgmts = "winmgmts:{impersonationLevel=impersonate}!//" & _server & "/" & cWMINameSpace
Set objWMIExchange = GetObject (strWinMgmts)
' Verify we were able to correctly connect to the WMI namesspace on the server
If Err.Number <> 0 Then
WScript.Echo "ERROR: Unable to connect to the WMI namespace."WScript.Echo err.description & " (" & Hex (err.number) & ")"
WScript.Quit 1
End If
' The Resources that currently exist appear as a list of
' Exchange_Mailbox instances in the Exchange namespace.
Set listExchange_Mailboxes = objWMIExchange.InstancesOf (cWMIInstance)
' Were any Exchange_Mailbox Instances returned?
If (listExchange_Mailboxes.count <= 0) Then
set objWMIExchange = Nothing
WScript.Echo "WARNING: No Exchange_Mailbox instances were returned."
WScript.Quit 1
End If
Dim count
count = 0
' Iterate through the list of Exchange_Mailbox objects.
For Each objExchange_Mailbox in listExchange_Mailboxes
If objExchange_Mailbox.Size > 400000 Then
Dim strTmp, strOut
count = count + 1
logfile.WriteLine("""" & objExchange_Mailbox.MailboxDisplayName & """,""" &
objExchange_Mailbox.Size & """,""" & objExchange_Mailbox.StoreName & """,""" &
objExchange_Mailbox.ServerName & """")
End If
Next
set objWMIExchange = Nothing
Next
Wscript.Echo "Completed