Skip to content

Instantly share code, notes, and snippets.

@jazzl0ver
Created March 1, 2018 15:03
Show Gist options
  • Save jazzl0ver/6972b90f0ef5afe6eca1704d3b90cd92 to your computer and use it in GitHub Desktop.
Save jazzl0ver/6972b90f0ef5afe6eca1704d3b90cd92 to your computer and use it in GitHub Desktop.
Send Exchange Server mailboxes size report
#
# Add similar action to the Task Scheduler:
# %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -file c:\utils\mailbox_report.ps1
#
$smtpServer = "mail.server.com"
$from = "[email protected]"
$to = "[email protected]"
$exchServer = "vm-exch16"
$file = "C:\Utils\MBSizes.csv"
. "C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1"
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue
Connect-ExchangeServer -auto
Get-MailboxStatistics -Server $exchServer | Select DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending | Export-CSV $file
$att = new-object Net.Mail.Attachment($file)
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = $from
$msg.To.Add($to)
#$msg.To.Add("[email protected]")
$msg.Subject = "$exchServer: mailbox stats"
$msg.Body = "Attached is the $exchServer mailbox report"
$msg.Attachments.Add($att)
$smtp.Send($msg)
$att.Dispose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment