Get Exchange mailboxes of disabled Active Directory accounts with PowerShell

Today a one liner:

I needed a list of Exchange mailboxes with disabled Active Directory accounts. Here is the command to display them in the PowerShell window:

Get-Mailbox | where {$_.ExchangeUserAccountControl -Match "AccountDisabled"} | fl DisplayName, Database, ExchangeUserAccountControl

If you want to create a csv file that lists all OWA enabled users but excludes all disabled accounts use the following command line (using Get-CASMailbox together with Get-Mailbox):

Get-Mailbox | where {$_.ExchangeUserAccountControl -ne "AccountDisabled"} | Get-CASMailbox | where {$_.OwaEnabled -eq "True"} | Select DisplayName, OwaEnabled | Export-Csv -Path ("{0}\Desktop\OWA.Users.csv" -f $env:USERPROFILE) -NoClobber -Encoding UTF8 -NoTypeInformation

This will create the list and save it as ‘OWA.Users.csv’ on the desktop of the executing account.

Leave a Reply

Your email address will not be published. Required fields are marked *