List of Active Directory users who do not have a Exchange 2013 mailbox

user6219126 picture user6219126 · May 17, 2016 · Viewed 7.7k times · Source

We delete users through Exchange 2013 which leaves behind the user account in Active Directory.

Using a PowerShell snippet, how can I get a list of Active Directory users who do not have a Exchange 2013 mailbox?

i.e. Active Directory users that need to be deleted.

Answer

Frode F. picture Frode F. · May 17, 2016

I'm confused. When you delete a mailbox in Exchange 2013, the AD user is also deleted. If you disable it the AD user is kept, but the attributes are removed. So if you really want to remove someone, why not delete the mailbox?

The primary difference between deleting and disabling a mailbox is that when you disable a mailbox, the Exchange attributes are removed from the corresponding Active Directory user account, but the user account is retained. When you delete a mailbox, both the Exchange attributes and the Active Directory user account are deleted.

Source: Disable or delete a mailbox @ TechNet

You could try to use the not-operator, ex:

Get-ADUser -LDAPFilter "(!msExchMailboxGuid=*)"

or

Get-ADUser -Filter '-not msExchMailboxGuid -like "*"'

or

Get-ADUser -Filter 'msExchMailboxGuid -notlike "*"'