rodrigosantosbr

Finding the Missing Mail Attribute in AD

Mar 17th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!

In a perfect world, everyone in Active Directory (AD) would have all of the proper attributes set - without any typos. :-) But we know. We're all humans so often times AD isn't perfect. By now, you probably know that in the GADS sync world the mail attribute should be set in AD. Fortunately, there's a cool set of PowerShell scripts that we can run to count how many folks are missing the mail attribute and who is missing the mail attribute.

You run these commands in PowerShell. PowerShell is usually found by going to Start | Administrative Tools | Active Directory Module for Windows PowerShell.

To Count How Many Users Are Missing the Mail Attribute for your Whole Domain, type:

Get-ADUser -LDAPFilter "(!(mail=*))" -resultSetSize $null | Measure-Object

To See What Users Are Missing the Mail Attribute for a Specific OU, type:

Get-ADUser -LDAPFilter "(!(mail=*))" -resultSetSize $null -searchbase "ou=students,dc=anyschool,dc=com"

You can also get fancy and pipe the output to a text file. Append a >c:\nomailattributecount.txt to the end either base statement. This will create a text file in the root of c:. For example, to get a text file of the users with no mail attribute set for a specific OU, you would type (or copy/paste):

Get-ADUser -LDAPFilter "(!(mail=*))" -resultSetSize $null -searchbase "ou=students,dc=anyschool,dc=com" >c:\studentswithnomailattset.txt

Working with schools implementing Google Apps and this awesome, helpful article were the inspiration of this page. The article discusses how to - on the fly - add the mail attribute based on the sAMAccountName attribute. Awesome stuff!

Hope it helps. Have fun!

Add Comment
Please, Sign In to add comment