Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm using this little script to show me the size of mailbox, usage, lastlogontime of all users mailboxes.

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

I would like to extend this information with information whether user account is enabled or disabled since I noticed that a lot of users have empty field lastlogontime so it seems like they never logged in (it's possible as we migrated 3 weeks ago).

share|improve this question

1 Answer 1

Account status (enabled/disabled) is not accessible directly in the EMS. I had to look in AD to get it and tie it to the Mailbox:

#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"
        }
    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.