mailbox sizes by information store

Posted on 2009-04-23
Last Modified: 2012-05-06
I am trying to write a script that will write the maibox names and sizes by information store to a csv file. I can get the mailbox and size information for the entire exchange server (or at least the administrative group I have rights to), but am having a hard time delimiting by information store. We have three and I would like to be able to write the information to a file which includes which information store the mailbox resides on as well as its size. Any help would be greatly appreciated!
On Error Resume Next

'Written to a file instead of Echoed on the screen


set objReadFSO = CreateObject ("Scripting.FileSystemObject")

set objOutputFile = objReadFSO.CreateTextFile("c:\Mailboxes.txt")


strComputer = ""

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & _



Set colItems = objWMIService.ExecQuery _

("Select * from Exchange_Mailbox")


For Each objItem in colItems


objOutputFile.Writeline objItem.MailboxDisplayName & _

"," & objItem.Size





Open in new window

Question by:rclaud10
    LVL 2

    Expert Comment

    are you bound to VB?  I have a powershell script that outputs mailbox size in descending order (in MB) by information store.  It outputs the file to a directory and emails them to me.  I've attached a part of it here:
    Get-MailboxStatistics -database "<servername>\<databasename>" | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount > c:\temp\NAMailboxStats\store1mailboxes.txt

    Open in new window


    Author Comment

    I am not bound to VB but am not familiar with powershell. I have yet to get a chance to look at powershell. I will certainly take this opportunity to do just that if it will accomplish what I need

    Author Comment

    would it be possible for you to forward the powershell script and just brief me on it? It would be extreemly appreciated!
    LVL 2

    Accepted Solution

    I'll post it here, I just wanted to know if you didn't mind it being in powershell.  I found the core of this code online and just updated it to meet my needs.  I've commented the code below and hopefully it will help you understand what it's doing.  You can save the script in a file with a ".ps1" extension and run it fron the Exchange Management Shell on any Exchange server, or your admin workstation (I've instructed my team to run it from their workstations because I don't like too many hands on the server).  

    I'm planning on getting this into Windows scheduler and perhaps adding a few more statistics into this, but for now it's a start and should accomplish what you want done.
    ###Send mailbox statistics script
    ###First, the administrator must change the mail message values in this section
    $FromAddress = ""
    #I've not figured out how to send this to multiple people, I guess a Distribution List would work here
    $ToAddress = ""
    $MessageSubject = "Mailbox Size Report"
    $MessageBody = "Attached is the current list of mailbox sizes."
    $SendingServer = ""
    ###Now get the stats and store in a text file
    ###The Get-MailboxStatistics cmdlet is being piped to various formatting commands so that the output file is easy to read.  You can change Size value to either KB or GB to match your needs.
    Get-MailboxStatistics -database "mailserver\Mailbox Database1" | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount > c:\temp\MailboxStats\1mailboxes.txt
    Get-MailboxStatistics -database "mailserver\Mailbox Database2" | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount > c:\temp\MailboxStats\2mailboxes.txt
    Get-MailboxStatistics -database "mailserver\Mailbox Database3" | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount > c:\temp\MailboxStats\3mailboxes.txt
    Get-MailboxStatistics -database "mailserver\Mailbox Database4" | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount > c:\temp\MailboxStats\4mailboxes.txt
    ###Create the mail message and add the statistics text file as an attachment
    $SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, 
    $MessageSubject, $MessageBody
    #Assign attachments to variables
    $Attachment1 = New-Object Net.Mail.Attachment("c:\temp\MailboxStats\1mailboxes.txt")
    $Attachment2 = New-Object Net.Mail.Attachment("c:\temp\MailboxStats\2mailboxes.txt")
    $Attachment3 = New-Object Net.Mail.Attachment("c:\temp\MailboxStats\3mailboxes.txt")
    $Attachment4 = New-Object Net.Mail.Attachment("c:\temp\MailboxStats\4mailboxes.txt")
    #Call variables and attach to message
    ###Send the message
    $SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer

    Open in new window

    LVL 70

    Assisted Solution

    by:Chris Dent

    Bear in mind that Get-MailboxStatistics will need you to be using Exchange 2007.

    If you happen to be using Exchange 2003 you can grab a function I wrote to act in the same way as Get-MailboxStatistics here:

    I would use Export-CSV rather than redirection to a text file, but the end results are likely to be very similar.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Set up iPhone and iPad email signatures to always send in high-quality HTML with this step-by step guide.
    Set OWA language and time zone in Exchange for individuals, all users or per database.
    In this video we show how to create a Contact 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 Recipients >> Contact ta…
    The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now