1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Get Exchange mailbox statistics on your email (Powershell)

Discussion in 'Scripting & Programming' started by LukeP, Oct 27, 2010.

  1. LukeP

    LukeP Gigabyte Poster

    I've written this for work but thought that someone else can find it useful.

    The script connects to Exchange server, gets the list of mailboxes and emails results to you in CSV file with following format:
    Name | Item Count | Size | Deleted Item Count | Deleted Item Size | Mailbox Database
    Script needs to be executed from EMS so below you can see batch script used to run it in case you want to get Task Scheduler to send you reports on regular basis.

    $EmailFrom = "from_address"
    $EmailTo = "to_address"
    $EmailSubject = "Weekly Mailbox Report"  
    $SMTPServer = ""
    Get-MailboxStatistics -Server <Exchange_Server_Name> |
    Sort-Object -Property TotalItemSize -Descending | 
    Select-Object -property DisplayName,@{N="ItemCount";E={$_.ItemCount}},
    				@{N="Database";E={$_.Database}} |
    Export-CSV -Path MailboxReport.csv -NoTypeInformation 
    Send-MailMessage -To "$EmailTo" -From "$EmailFrom" -subject "$EmailSubject" 
    -Attachments "MailboxReport.csv" -smtpServer "$SMTPServer"
    You will need to provide email addresses (from and to), SMTP server IP address (doesn't seem to work with hostnames for some reason) and Exchange Server name in Get-MailboxStatistics cmdlet.

    To add it to task scheduler use batch file.

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command 
    ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; 
    Connect-ExchangeServer -auto; C:\EXCHANGE_Scripts\ReportMailboxSizes.ps1"
    Modify path to ReportMailboxSizes.ps1 file. It's basically target entry from EMS shortcut in start menu with semicolon and path to our script at the end.

    It requires Powershell v2 due to new mail sending cmdlet. Tested with Exchange 2010.

    Hopefully someone fill find it useful.

    Any questions, just ask.
    Last edited: Oct 27, 2010
    WIP: Uhmm... not sure
  2. zebulebu

    zebulebu Terabyte Poster

    Yeeeeeah. Nice one MS - remove something from the GUI and make people p155 around with scripting instead to get the info you need. If I wanted to do that, I'd run an opensource mail server and save myself a sh1tload of cash. Removing stuff like this from the ESM is yet another in a long line of stupidness from MS. If it's all the same with you, MS, I'll stick with 2003 (which works, is stable to the point of ridiculousness and doesn't require me to write forty lines of code to do the same thing as 'right-click - export')

    Kudos to you for the script though Luke - nice one.
    Certifications: A few
    WIP: None - f*** 'em

Share This Page