使用此脚本可以从邮箱中获取一些相关的信息。
[Array] $mbcombCollection = @()
# Get every staff mailbox
Get-Mailbox -ResultSize Unlimited -Filter {CustomAttribute1 -eq "STAFF"} | Select Identity, PrimarySmtpAddress | ForEach {
# Get the DisplayName, LastLogonTime, DatabaseName and TotalItemSize statistics
$mbStats = Get-MailboxStatistics $_.identity | Select DisplayName, LastLogonTime, DatabaseName, TotalItemSize
# Get the statistics for Sent and Deleted Items
$mbSentStats = Get-MailboxFolderStatistics $_.identity | Where {$_.FolderPath -eq "/Sent Items"} | Select ItemsInFolderAndSubfolders, @{name="SentItemsSize";expression={$_.FolderAndSubfolderSize.ToMB()}}
$mbDeletedStats = Get-MailboxFolderStatistics $_.identity | Where {$_.FolderPath -eq "/Deleted Items"} | Select ItemsInFolderAndSubfolders, @{name="DeletedItemsSize";expression={$_.FolderAndSubfolderSize.ToMB()}}
$mbcomb = "" | Select "Display Name", "Last Logon Time", Database, "Mailbox Size (MB)", "Total Sent Items", "Sent Items Size (MB)", "Total Deleted Items", "Deleted Items Size (MB)", "E-mail Address"
$mbcomb."Display Name" = $mbStats.DisplayName
$mbcomb."Last Logon Time" = $mbStats.LastLogonTime
$mbcomb.Database = $mbStats.DatabaseName
$mbcomb."Mailbox Size (MB)" = [math]::round($mbStats.TotalItemSize.Value.ToMB(), 2)
$mbcomb."Total Sent Items" = $mbSentStats.ItemsInFolderAndSubfolders
$mbcomb."Sent Items Size (MB)" = [math]::round($mbSentStats.SentItemsSize, 2)
$mbcomb."Total Deleted Items" = $mbDeletedStats.ItemsInFolderAndSubfolders
$mbcomb."Deleted Items Size (MB)" = [math]::round($mbDeletedStats.DeletedItemsSize, 2)
$mbcomb."E-mail Address" = $_.PrimarySmtpAddress
$mbcombCollection += $mbcomb
}
$mbcombCollection | Export-Csv D:\Scripts\Reports\"MailboxStats_STAFF_$(Get-Date -f 'yyyyMMdd').csv" -NoType