您的位置:首页 > 其它

花了一上午,合成的一个粗糙的IT用来了解EXCHANGE运行情况的自动邮件脚本

2013-04-19 15:59 323 查看
看着简单,格式不好。

但也让IT能了解EXCHANGE 2010的MAIL DATABASE的空间占用,WHITE SPACE闲置空间情况,每个用户占用的大小。

代码也使用了输出为HTML,发送多个邮件,同时发送多个HTML作EMAIL BODY。因为附近毕竟要打开多次。

原始参考贴及后续操作:

http://www.mikepfeiffer.net/2010/03/exchange-2010-database-statistics-with-powershell/

Then you could schedule the .ps1 script to run as needed. So let’s say you saved the above code to c:\dbreport.ps1, you could schedule the following command to run on the server:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; c:\dbreport.ps1"

If you aren’t already familiar with scheduling Exchange 2010 PowerShell scripts check out this post.

function Get-DatabaseStatistics {
$Databases = Get-MailboxDatabase -Status
foreach($Database in $Databases) {
$DBSize = $Database.DatabaseSize
$MBCount = @(Get-MailboxStatistics -Database $Database.Name).Count

$MBAvg = Get-MailboxStatistics -Database $Database.Name |
%{$_.TotalItemSize.value.ToMb()} |
Measure-Object -Average

New-Object PSObject -Property @{
Server = $Database.Server.Name
DatabaseName = $Database.Name
MailboxCount = $MBCount
"DatabaseSize (GB)" = $DBSize.ToGB()
"AverageMailboxSize (MB)" = $MBAvg.Average
"WhiteSpace (GB)" = $Database.AvailableNewMailboxSpace.ToGB()
}
}
}

Get-DatabaseStatistics | ConvertTo-HTML | Out-File c:\autops1\report.html

Get-MailboxStatistics -Database "AAA" | Select DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending | ConvertTo-HTML | Out-File c:\autops1\AAA.html
。。。。
Get-MailboxStatistics -Database "BBB" | Select DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending | ConvertTo-HTML | Out-File c:\autops1\BBB.html

$recipients = "AAA <AAA@>", "BBB <BBB@>", "CCC <CCC@>"
$htmlfile = "c:\autops1\report.html", "AAA.html",..."c:\autops1\CCC.html"

Send-MailMessage -To $recipients -From EEE@com -Subject " Exchange Database Statistics for $((get-date).ToShortDateString())" -SmtpServer  D.D.D.D -BodyAsHtml (Get-Content $htmlfile | Out-String)


输出样本:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐