Need script to check mail attribute domain only in Acrive Directory

This topic contains 6 replies, has 5 voices, and was last updated by  Dan Potter 2 years, 8 months ago.

  • Author
  • #31907

    Gary Seven

    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. ( just
    I want the script to search all email's in AD ending in domain "" and then add that user to a security group. ( memberof tab)
    Is there a sample i can use?

  • #31908

    Curtis Smith

    Use Get-ADUser to get your users using -filter to filter on your email address

    Get-ADUser -filter "mail -like '*"

    Then use Add-ADGroupMember to add those users to your group.

  • #31928

    Gary Seven

    Thanks that worked. I will filter for recursive since it only pulls a few emails

  • #31929

    Paul Johnston

    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 e-mail address and not just ones who have it set as their primary SMTP address. Depends on your requirements though.

  • #32014

    Gary Seven

    I am not seeing the "proxyAddresses" attribute in the AD attribute editor. Is that for extended AD / Exchange?

  • #32025


    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?

  • #32082

    Dan Potter

    The mail attribute doesn't necessarily match proxyaddresses.

    get-aduser -Filter {anr -like "smtp:*"} |select -First 1

You must be logged in to reply to this topic.