批量获取Exchange邮箱用户使用量

" title="快乐分享(zhuzengju个人blog)


0

批量获取Exchange邮箱用户使用量

编辑:管理员/ 栏目:电子邮件 /发布于:2023年-3月-7日

转载自https://blog.51cto.com/jialt/1768198

微软官网 https://gallery.technet.microsoft.com/scriptcenter/Exchange-2010-2013-2016-cee5e558。提供了这个脚本,脚本实现的功能和51CTO作者需要实现的功能大体一致,下面51CTO作者改造后的脚本,转载分享给大家。一切解释归51CTO作者https://blog.51cto.com/jialt/1768198

1、脚本实现的功能
   脚本邮箱用户的脚本批量去获取邮箱用户的信息(显示名称、登录名、OU信息、邮箱配额、邮箱邮件数量、邮箱已使用大小、邮箱地址、邮箱容量使用情况等信息)

2、脚本运行环境
   目前该脚本可以用来获取Exchange 2010/2013。至于Exchange 2016目前还未进行测试。

3、修复了原脚本中的如下不足之处:
1)、修复显示名称中包含中文时显示乱码问题。
2)、添加了判断当用户邮箱设置了自定义配额且自定义配额设定为无限制时,脚本自动判断条件。
3)、添加了计算用户邮箱使用量(百分比)。
4)、添加了用户邮箱配额设定为数据库配额,且数据库配额设定为无限制时,脚本自动判断条件。
4、脚本内容:

#--------------------------------------------下面为脚本正文内容,直接复制如下内容,然后保存为.ps1-------------------------------------------------
Param(  
    [Parameter(Mandatory = $true)]    
    [string] $CSVPath    
)

$Mailboxes = Get-Mailbox -ResultSize Unlimited
$CSV = @()  
foreach($Mailbox in $Mailboxes)    
    {    
        $MailboxStats = (Get-MailboxStatistics $Mailbox -WarningAction SilentlyContinue )
        if ($mailbox.UseDatabaseQuotaDefaults -eq $true)  
            {    
                if((Get-MailboxDatabase $mailbox.Database).ProhibitSendReceiveQuota.Value -eq $null)    
                    {    
                        $ProhibitSendReceiveQuota=0    
                    }    
                if((Get-MailboxDatabase $mailbox.Database).ProhibitSendReceiveQuota.Value -ne $null)    
                    {    
                       $ProhibitSendReceiveQuota=(Get-MailboxDatabase $mailbox.Database).ProhibitSendReceiveQuota.Value.ToMB()    
                    }    
            }    
        if ($mailbox.UseDatabaseQuotaDefaults -eq $false)    
            {    
                if($mailbox.ProhibitSendReceiveQuota.Value -eq $null)    
                    {    
                        $ProhibitSendReceiveQuota=0    
                    }    
                if($mailbox.ProhibitSendReceiveQuota.Value  -ne $null)    
                    {    
                        $ProhibitSendReceiveQuota=$mailbox.ProhibitSendReceiveQuota.Value.ToMB()    
                    }               
            }

        $CSVLine = New-Object System.Object  
        $CSVLine | Add-Member -Type NoteProperty -Name "DisplayName" -Value $Mailbox.DisplayName    
        $CSVLine | Add-Member -Type NoteProperty -Name "UserName" -Value $Mailbox.SamAccountName    
        $CSVLine | Add-Member -Type NoteProperty -Name "PrimarySMTP" -Value $Mailbox.WindowsEmailAddress    
        $CSVLine | Add-Member -Type NoteProperty -Name "OrganizationalUnit" -Value $Mailbox.OrganizationalUnit    
        $CSVLine | Add-Member -Type NoteProperty -Name "EmailAliases" -Value ($Mailbox.EmailAddresses.SmtpAddress -join "; ")    
        if($MailboxStats)    
            {    
                if($ProhibitSendReceiveQuota -eq 0)    
                    {    
                        $CSVLine | Add-Member -Type NoteProperty -Name "TotalItemSizeInMB" -Value $MailboxStats.TotalItemSize.Value.ToMB()    
                        $CSVLine | Add-Member -Type NoteProperty -Name "ItemCount" -Value $MailboxStats.ItemCount    
                        $CSVLine | Add-Member -Type NoteProperty -Name "StorageLimitStatus" -Value $Mailbox.StorageLimitStatus    
                        $CSVLine | Add-Member -Type NoteProperty -Name "UseDatabaseQuotaDefaults" -Value $Mailbox.UseDatabaseQuotaDefaults    
                        $CSVLine | Add-Member -Type NoteProperty -Name "ProhibitSendReceiveQuotaInMB" -Value "此用户无配额限制"    
                        $CSVLine | Add-Member -Type NoteProperty -Name '邮箱使用情况(%)' -Value "此用户无配额限制"    
                    }    
                if($ProhibitSendReceiveQuota -ne 0)    
                    {    
                         $CSVLine | Add-Member -Type NoteProperty -Name "TotalItemSizeInMB" -Value $MailboxStats.TotalItemSize.Value.ToMB()    
                         $CSVLine | Add-Member -Type NoteProperty -Name "ItemCount" -Value $MailboxStats.ItemCount    
                         $CSVLine | Add-Member -Type NoteProperty -Name "StorageLimitStatus" -Value $Mailbox.StorageLimitStatus    
                         $CSVLine | Add-Member -Type NoteProperty -Name "UseDatabaseQuotaDefaults" -Value $Mailbox.UseDatabaseQuotaDefaults    
                         $CSVLine | Add-Member -Type NoteProperty -Name "ProhibitSendReceiveQuotaInMB" -Value $ProhibitSendReceiveQuota    
                         $UsedSpace=[int]($MailboxStats.TotalItemSize.Value.ToMB()*100/$ProhibitSendReceiveQuota)    
                         $CSVLine | Add-Member -Type NoteProperty -Name '邮箱使用情况(%)' -Value ("$UsedSpace"+"%")    
                    }    
             }    
        $CSV+=$CSVLine    
    }

$CSV | Sort TotalItemSize -Descending | Export-Csv -NoTypeInformation $CSVPath -Encoding Unicode

#-------------------------------------脚本内容结束---------------------------------------------------------------------


统计Exchange收发邮件总数:
发送邮件总数(内部+外部):
Get-ExchangeServer | Get-MessageTrackingLog -Start "2023/05/01 00:00:00" -end "2023/06/01 00:00:00" -EventId send| Measure-object



接收邮件总数(内部+外部)
Get-ExchangeServer | Get-MessageTrackingLog -Start "2023/05/01 00:00:00" -end "2023/06/01 00:00:00" -EventId Receive | Measure-object


统计每台服务器的邮件接收总量
Get-ExchangeServer | Get-MessageTrackingLog -ResultSize unlimited  -Start "2023/05/01 00:00:00" -end "2023/06/01 00:00:00" -EventId Receive | Measure-object

统计每台服务器的邮件发送总量
Get-ExchangeServer | Get-MessageTrackingLog -ResultSize unlimited  -Start "2023/05/01 00:00:00" -end "2023/06/01 00:00:00" -EventId Send | Measure-object

本文由“快乐分享(zhuzengju个人blog) > 管理员”整理编辑。


未注明为原创的文章以及每篇文章的评论内容都不代表本站观点,本站不对此内容的真实性及言论负责。如您发表评论意见,视为同意本站记录言论您的来源IP地址信息及发表时间。

如果喜欢这篇文章,欢迎订阅快乐分享(zhuzengju个人blog)以获得最新内容。

已经有 0 条群众意见