' USAGE: cscript MailboxSize.vbs SERVERNAME MAILBOXNAME ' Requires that CDO 1.21 be installed on the machine. ' This script is provided AS IS. It is intended as a SAMPLE only. ' Microsoft offers no warranty or support für this script. ' use at your own risk. ' Get command line arguments Dim obArgs Dim cArgs Set obArgs = WScript.Arguments cArgs = obArgs.Count Main Sub Main() Dim oSession Dim oInfoStores Dim oInfoStore Dim StorageUsed Dim NumMessages Dim strProfileInfo On Error Resume Next If cArgs <> 2 Then WScript.Echo "Usage: cscript MailboxSize.vbs SERVERNAME MAILBOXNAME" Exit Sub End If 'Create Session object Set oSession = CreateObject("MAPI.Session") if Err.Number <> 0 Then WScript.Echo "Error creating MAPI.Session object. Make sure CDO 1.21 is installed." WScript.Echo Err.Number & " " & Err.Description Exit Sub End If strProfileInfo = obArgs.Item(0) & vbLf & obArgs.Item(1) 'Logon oSession.Logon , , False, True, , True, strProfileInfo if Err.Number <> 0 Then WScript.Echo "Error Logging On: " & Err.Number & " " & Err.Description WScript.Echo "Server: " & obArgs.Item(0) WScript.Echo "Mailbox: " & obArgs.Item(1) Set oSession = Nothing Exit Sub End If 'Grab the info stores Set oInfoStores = oSession.InfoStores if Err.Number <> 0 Then WScript.Echo "Error Retrieving InfoStores Collection: " & Err.Number & " " & Err.Description WScript.Echo "Server: " & obArgs.Item(0) WScript.Echo "Mailbox: " & obArgs.Item(1) Set oInfoStores = Nothing Set oSession = Nothing Exit Sub End If 'Loop through info stores to find User's mailbox For Each oInfoStore In oInfoStores If InStr(1, oInfoStore.Name, "Mailbox - ", 1) <> 0 Then StorageUsed = oInfoStore.Fields(&HE080003) '&HE080003 = PR MESSAGE SIZE if Err.Number <> 0 Then WScript.Echo "Error Retrieving PR MESSAGE SIZE: " & Err.Number & " " & Err.Description WScript.Echo "Server: " & obArgs.Item(0) WScript.Echo "Mailbox: " & obArgs.Item(1) Set oInfoStore = Nothing Set oInfoStores = Nothing Set oSession = Nothing Exit Sub End If NumMessages = oInfoStore.Fields(&H36020003) '&H33020003 = PR CONTENT COUNT if Err.Number <> 0 Then WScript.Echo "Error Retrieving PR CONTENT COUNT: " & Err.Number & " " & Err.Description WScript.Echo "Server: " & obArgs.Item(0) WScript.Echo "Mailbox: " & obArgs.Item(1) Set oInfoStore = Nothing Set oInfoStores = Nothing Set oSession = Nothing Exit Sub End If WScript.Echo "Storage used in " & oInfoStore.Name & " (bytes): " & StorageUsed WScript.Echo "Number of Messages: " & NumMessages End If Next ' Log off oSession.Logoff ' Clean up Memory Set oInfoStore = Nothing Set oInfoStores = Nothing Set oSession = Nothing End Sub