Link to home
Start Free TrialLog in
Avatar of worsnoptr
worsnoptrFlag for United States of America

asked on

I want a script that will pull the total mailbox size for a given user from exchange 2003

I woul like to give my helpdesk staff a script that the can type the username in a pop up box and have a wscript that will tell them the total mailbox size and maybe even what folders contain what, so they will stop asking me to pull the info from exchange.
I have attached the script i am currently using but have to do it via the command line and type in the server name I tried to modify it so i could use a input pop up for the username and then use the mailboxname to find the servername in aduc and use that info to drive the script but i keep getting errors. What do i have to modify to make this happen without getting errors.
' USAGE: cscript MailboxSize.vbs SERVERNAME MAILBOXNAME
 
' This requires that CDO 1.21 is installed on the computer.
' This script is provided AS IS. It is intended as a SAMPLE only.
' Microsoft offers no warranty or support for 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
   Dim sMsg
 
   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
      sMsg = "Error creating MAPI.Session."
      sMsg = sMsg & "Make sure CDO 1.21 is installed. "
      sMsg = sMsg & Err.Number & " " & Err.Description
      WScript.Echo sMsg
      Exit Sub
   End If
    
   strProfileInfo = obArgs.Item(0) & vbLf & obArgs.Item(1)
 
   'Log on.
   oSession.Logon , , False, True, , True, strProfileInfo
   if Err.Number <> 0 Then
      sMsg = "Error logging on: "
      sMsg = sMsg & Err.Number & " " & Err.Description
      WScript.Echo sMsg
      WScript.Echo "Server: " & obArgs.Item(0)
      WScript.Echo "Mailbox: " & obArgs.Item(1)
      Set oSession = Nothing
      Exit Sub
   End If
 
   'Grab the information stores.
   Set oInfoStores = oSession.InfoStores
   if Err.Number <> 0 Then
 
      sMsg = "Error retrieving InfoStores Collection: "
      sMsg = sMsg & Err.Number & " " & Err.Description
      WScript.Echo sMsg
      WScript.Echo "Server: " & obArgs.Item(0)
      WScript.Echo "Mailbox: " & obArgs.Item(1)
      Set oInfoStores = Nothing
      Set oSession = Nothing
      Exit Sub
   End If
    
   'Loop through information stores to find the user's mailbox.
   For Each oInfoStore In oInfoStores
      If InStr(1, oInfoStore.Name, "Mailbox - ", 1) <> 0 Then
         '&HE080003 = PR_MESSAGE_SIZE
         StorageUsed = oInfoStore.Fields(&HE080003)
         if Err.Number <> 0 Then
            sMsg = "Error retrieving PR_MESSAGE_SIZE: "
            sMsg = sMsg & Err.Number & " " & Err.Description
            WScript.Echo sMsg
            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
         
         '&H33020003 = PR_CONTENT_COUNT
         NumMessages = oInfoStore.Fields(&H36020003)
 
         if Err.Number <> 0 Then
 
            sMsg = "Error Retrieving PR_CONTENT_COUNT: "
            sMsg = sMsg & Err.Number & " " & Err.Description
            WScript.Echo sMsg
            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
 
         sMsg = "Storage Used in " & oInfoStore.Name
         sMsg = sMsg & " (Megabytes): " & Int(StorageUsed / 1048576)
         WScript.Echo sMsg
         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

Open in new window

Avatar of exx1976
exx1976
Flag of United States of America image

Users can get this info themselves..  Just go into the folder view of Outlook, right click the mailbox, select properties, then click "Folder Size"..  Viola, complete breakdown of everything, folder by folder..


With the method you suggest, the helpdesk staff would all have to be Exchange Administrators..  Or, at the very least, have permission to logon to everyone's mailbox..
Avatar of worsnoptr

ASKER

They have permissions to view the mailbox size the script is working just fine i am just trying to simplify the proccess. I also don't want to involve users into the proccess. or use esm for that matter
ASKER CERTIFIED SOLUTION
Avatar of exx1976
exx1976
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Almost forgot..  Make sure to edit line 27 to put the name of your Exchange server in there, since I'm fairly confident it's not "MailServer"

LOL
I didn't work at first so i replaced line 27    ServerName = "MailServer" with ServerName = "MY-mailserver" and it works with all of my mail servers even though i only used one server name i don't know if that's what you wanted me to do or if it was supposed to be a varible but it made it work so thanks.