切换到宽版
  • 5606阅读
  • 0回复

[求助]使用脚本从邮箱中获取信息 [复制链接]

上一主题 下一主题
 
只看楼主 倒序阅读 0楼  发表于: 2011-03-19
— 本帖被 YOYO 从 Exchange 脚本中心 移动到本区(2015-06-25) —
  • 脚本环境:PowerShell
  • 适合版本:Exchange 2007
  • 适用平台:
使用此脚本可以从邮箱中获取一些相关的信息。

[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
分享到
快速回复
限60 字节
 
上一个 下一个