[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 947
  • Last Modified:

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 = "sirny-ne-exch1.sirny.ne.nrt"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & _
"\ROOT\MicrosoftExchangeV2")
 
Set colItems = objWMIService.ExecQuery _
("Select * from Exchange_Mailbox")
 
For Each objItem in colItems
 
objOutputFile.Writeline objItem.MailboxDisplayName & _
"," & objItem.Size
 
Next
 
objOutputFile.Close

Open in new window

0
rclaud10
Asked:
rclaud10
  • 2
  • 2
2 Solutions
 
darknothCommented:
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

0
 
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
0
 
rclaud10Author Commented:
would it be possible for you to forward the powershell script and just brief me on it? It would be extreemly appreciated!
0
 
darknothCommented:
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 = "MailboxStats@domain.com"
#I've not figured out how to send this to multiple people, I guess a Distribution List would work here
$ToAddress = "admin@wiley.com"
$MessageSubject = "Mailbox Size Report"
$MessageBody = "Attached is the current list of mailbox sizes."
$SendingServer = "smtpserver.domain.com"
 
###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
$SMTPMessage.Attachments.Add($Attachment1)
$SMTPMessage.Attachments.Add($Attachment2)
$SMTPMessage.Attachments.Add($Attachment3)
$SMTPMessage.Attachments.Add($Attachment4)
 
###Send the message
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)

Open in new window

0
 
Chris DentPowerShell 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:

http://www.highorbit.co.uk/?p=871

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

Chris
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now