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

worsnoptrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

exx1976Commented:
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..
0
worsnoptrAuthor Commented:
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
0
exx1976Commented:
My apologies, I didn't review your code very closely upon my first post.

I have made the changes you're after.  Remember:  test, test, and test again.

Good luck!
' 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
   Dim ServerName
   Dim Mailbox
   
   ServerName = "MailServer"
   Mailbox = InputBox("Enter the mailbox name you wish you check","Mailbox Name?")
   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 = ServerName & vbLf & Mailbox
 
   '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: " & ServerName
      WScript.Echo "Mailbox: " & Mailbox
      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: " & ServerName
      WScript.Echo "Mailbox: " & Mailbox
      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: " & ServerName
            WScript.Echo "Mailbox: " & Mailbox
            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: " & ServerName
            WScript.Echo "Mailbox: " & Mailbox
            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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
exx1976Commented:
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
0
worsnoptrAuthor Commented:
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.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.