星期五, 7月 18, 2008

Exchange 2007 郵箱大小寄送郵件報告 powershell script

###Send mailbox statistics script

###First, the administrator must change the mail message values in this section
# 寄件者為 MailboxReport@abc.com
$FromAddress = "MailboxReport@abc.com"
# 收件者為 admin@abc.com
$ToAddress = "admin@abc.com"
# 郵件標題
$MessageSubject = "Mailbox Size Report"
# 郵件內容
$MessageBody = "Attached is the current list of mailbox sizes."
# 送件伺服器
$SendingServer = "stl-relay"

###Now get the stats and store in a text file
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}}, ItemCount > mailboxes.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
$Attachment = New-Object Net.Mail.Attachment("mailboxes.txt")
$SMTPMessage.Attachments.Add($Attachment)

###Send the message
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)

沒有留言: