Solved

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

Posted on 2008-10-21
5
303 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:worsnoptr
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:exx1976
ID: 22769680
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
 

Author Comment

by:worsnoptr
ID: 22769869
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
 
LVL 18

Accepted Solution

by:
exx1976 earned 500 total points
ID: 22770156
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
 
LVL 18

Expert Comment

by:exx1976
ID: 22770188
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
 

Author Closing Comment

by:worsnoptr
ID: 31508418
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

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…
how to add IIS SMTP to handle application/Scanner relays into office 365.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question