mailbox sizes by information store

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

Who is Participating?
darknothConnect With a Mentor Commented:
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

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

rclaud10Author Commented:
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
rclaud10Author Commented:
would it be possible for you to forward the powershell script and just brief me on it? It would be extreemly appreciated!
Chris DentConnect With a Mentor PowerShell DeveloperCommented:

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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.