Exchange Powershell script for mailbox statistics via email

The below powershell script will get the size and item count of each Exchange mailbox and send a .txt file via email to the configured recipient.

###Send mailbox statistics script

###Now get the stats and store in a text file
Get-Mailbox -Resultsize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label=”TotalItemSize(MB)”;expression={$_.TotalItemSize.Value.ToMB()}},ItemCount | Out-File -FilePath c:\mailboxes.txt

function sendmail($body)
{
$SmtpClient = new-object system.net.mail.smtpClient
$MailMessage = New-Object system.net.mail.mailmessage
$SmtpClient.Host = “IP Address of SMTP server”
$mailmessage.from = “fromaddress@domain.com”
$mailmessage.To.add(“toaddress@domain.com”)
$mailmessage.Subject = “Exchange 2007 Mailbox Sizes”
$MailMessage.IsBodyHtml = $false
$mailmessage.Attachments.Add(“C:\mailboxes.txt”)
$smtpclient.Send($mailmessage)

}
sendmail

Advertisements
This entry was posted in Exchange 2007 Powershell commands and scripts. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s