看着简单,格式不好。
但也让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.
1 function Get-DatabaseStatistics { 2 $Databases = Get-MailboxDatabase -Status 3 foreach($Database in $Databases) { 4 $DBSize = $Database.DatabaseSize 5 $MBCount = @(Get-MailboxStatistics -Database $Database.Name).Count 6 7 $MBAvg = Get-MailboxStatistics -Database $Database.Name | 8 %{$_.TotalItemSize.value.ToMb()} | 9 Measure-Object -Average 10 11 New-Object PSObject -Property @{ 12 Server = $Database.Server.Name 13 DatabaseName = $Database.Name 14 MailboxCount = $MBCount 15 "DatabaseSize (GB)" = $DBSize.ToGB() 16 "AverageMailboxSize (MB)" = $MBAvg.Average 17 "WhiteSpace (GB)" = $Database.AvailableNewMailboxSpace.ToGB() 18 } 19 } 20 } 21 22 Get-DatabaseStatistics | ConvertTo-HTML | Out-File c:\autops1\report.html 23 24 Get-MailboxStatistics -Database "AAA" | Select DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending | ConvertTo-HTML | Out-File c:\autops1\AAA.html 25 。。。。 26 Get-MailboxStatistics -Database "BBB" | Select DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending | ConvertTo-HTML | Out-File c:\autops1\BBB.html 27 28 $recipients = "AAA <AAA@>", "BBB <BBB@>", "CCC <CCC@>" 29 $htmlfile = "c:\autops1\report.html", "AAA.html",..."c:\autops1\CCC.html" 30 31 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)
输出样本:
时间: 2024-12-09 07:15:54