Auto Email Exchange 2007 Mailbox Report

Hi all. I’ve written this simple PowerShell script to output your user mailboxes, their total size and the item count – the script will then email the output to a specified account in a pretty HTML table format. Feel free to download the .ps1 file and run it as you wish.

Remember that you need to “Set-ExecutionPolicy RemoteSigned” in the Task Scheduler for the PS script to run correctly. Also, if you are going to run this PS script on a remote server you may need to add the MSExchange PS Snappin. To do this just add “Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin” to the first line of the script. You obviously need to change the mail server and recipient options.

Here’s the script download EmailMailboxSizeReport.ps1

And a break down of the script:

#Firstly, get the users mailbox… ONLY objects that are UserMailbox and not HiddenFromAddressListsEnabled
$MailboxUser = Get-Mailbox | Where {($_.RecipientType -eq “UserMailbox”) -and ($_.HiddenFromAddressListsEnabled -eq $False)}

#Secondly, get the mailbox statistics for the selected users. Some formatting also
$MessageBody = $MailboxUser | Get-MailboxStatistics | Sort-Object TotalItemSize | Select DisplayName, ItemCount, @{Expression={$_.TotalItemSize.Value.ToMB()};Name=”MailboxSize MB”} | ConvertTo-html

#Finally, enter your mail server details
$FromAddress = “FromAddress@YourDomain.com”
$ToAddress = “ToAddress@YourDomain.com”
$MessageSubject = “PowerShell Report Subject”
$SendingServer = “YourMailServerAddress”
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody
$SMTPMessage.IsBodyHtml = $true
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)

#Written by Matt Shadbolt
#http://www.mattlog.net

Tags: , , , ,

5 Responses
Filed under:Uncategorized

5 Responses to “Auto Email Exchange 2007 Mailbox Report”

  • Paul Says:

    This is what I was looking for.
    I added “-Descending” and all is very nice.
    Thanks.
    Paul

  • miraaj Says:

    Thank you :)
    it works also on Exchange 2010

  • Chad Hammond Says:

    I am getting this error any idea? I am running Exchange 2010.

    Security Warning
    Run only scripts that you trust. While scripts from the Internet can be useful, this script can potentially harm your
    computer. Do you want to run C:\Users\User\Desktop\emailmailboxsizereport.ps1?
    [D] Do not run [R] Run once [S] Suspend [?] Help (default is “D”): r
    Mailbox ‘Domain.com/Domain/MIS/Service Accounts/Help Desk’ doesn’t exist in an Exchange 2007 or later mailbo
    x database.
    + CategoryInfo : InvalidArgument: (LINK:Server) [Get-MailboxStatistics], MdbAdminTaskException
    + FullyQualifiedErrorId : E173C872,Microsoft.Exchange.Management.MapiTasks.GetMailboxStatistics

    Exception calling “Send” with “1″ argument(s): “Failure sending mail.”
    At C:\Users\_chammond\Desktop\emailmailboxsizereport.ps1:15 char:17
    + $SMTPClient.Send <<<< ($SMTPMessage)
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

  • Matt Shadbolt Says:

    I haven’t tried running this in 2010. Can you post or email the script?

  • Shashi Says:

    I am getting below error while executing this PS script for exchange 2007 server
    Exception calling “Send” with “1″ argument(s): “Failure sending mail.”
    At D:\SHL_Server_Team\Scripts\Exchange\emailmailboxsizereport.ps1:15 char:17
    + $SMTPClient.Send <<<< ($SMTPMessage)
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Leave a Reply