如何在 Exchange 2010 EMS 中显示禁用/启用状态

如何在 Exchange 2010 EMS 中显示禁用/启用状态

我正在使用这个小脚本来显示所有用户邮箱的大小、使用情况和上次登录时间。

Get-MailboxDatabase "MDB01" | Get-MailboxStatistics | Sort totalitemsize -desc | ft displayname, totalitemsize, @{label=”TotalItemSize(MB)”;expression={$_.TotalItemSize.Value.ToMB()}}, itemcount, lastlogontime > C:\MailboxReport.txt
Get-MailboxDatabase "MDB02" | Get-MailboxStatistics | Sort totalitemsize -desc | ft displayname, totalitemsize, @{label=”TotalItemSize(MB)”;expression={$_.TotalItemSize.Value.ToMB()}}, itemcount, lastlogontime >> C:\MailboxReport.txt

我想扩展此信息,以提供有关用户帐户是否启用或禁用的信息,因为我注意到很多用户的 lastlogontime 字段为空,所以看起来他们从未登录过(这是可能的,因为我们在 3 周前迁移了)。

答案1

无法在 EMS 中直接访问帐户状态(已启用/已禁用)。我必须在 AD 中查找才能获取它并将其绑定到邮箱:

#Import Exchange Module (Change this path to wherever this file lives)
Import-Module C:\Temp\Exchange.psm1
#List of Mailbox Databases
$MDBs = @("MDB01","MDB02")
ForEach ($MDB in $MDBs) {
    #Get List of Mailboxes in the db
    $mailboxes = Get-MailboxDatabase $MDB | Get-MailboxStatistics
    #Add a semi-colon separated header line to the output file
    ac C:\Temp\Mailboxes.txt "DisplayName;TotalItemSize;ItemCount;LastLogonTime;AccountStatus"
    #Loop through each Mailbox and search AD to obtain account status
    ForEach ($user in $mailboxes) {
        #The filter ties the AD search to the specific mailbox in the loop
        $Filter = "(&(objectCategory=person)(objectClass=user)(legacyExchangeDN=$($user.LegacyDN)))"
        $AD = ([adsiSearcher]$Filter).findone()
        #Puts the UserAccountControl attribute into readable status
        #NOTE: the values I used are from my own observations to determine account status and may not be 100% accurate
        if ($AD.properties.item("userAccountControl") -eq 512 -or $AD.properties.item("userAccountControl") -eq 66048) { $acct = "Enabled" }
            else { $acct = "Disabled" }
        #Add a line to the output file with all the info we want
        ac C:\Temp\mailboxes.txt "$($user.displayname);$($user.totalitemsize);$($user.itemcount);$($user.lastlogontime);$acct"
        }
    }

相关内容