I need to be able to run a script to get the Active Directory users email by domain name. The part on the right of the @ sign ex. JohnDoe@acme.com ( just acme.com
I want the script to search all email’s in AD ending in domain “acme.com” and then add that user to a security group. ( memberof tab)
Is there a sample i can use?
Use Get-ADUser to get your users using -filter to filter on your email address
Get-ADUser -filter "mail -like '*@myemaildomain.com"
Then use Add-ADGroupMember to add those users to your group.
Thanks that worked. I will filter for recursive since it only pulls a few emails
The ‘Mail’ attribute specifies the users primary SMTP address.Querying the ‘proxyAddresses’ attribute might work better if you’re looking for any users who have an @acme.com e-mail address and not just ones who have it set as their primary SMTP address. Depends on your requirements though.
I am not seeing the “proxyAddresses” attribute in the AD attribute editor. Is that for extended AD / Exchange?
proxyAddresses is an Exchange attribute. It holds the multiple X400, X509, SIP & SMTP addresses for the user.
If you do not have Exchange, what email system do you have?
The mail attribute doesn’t necessarily match proxyaddresses.
get-aduser -Filter {anr -like “smtp:*mydomain.com”} |select -First 1