Need script to check mail attribute domain only in Acrive Directory

This topic contains 6 replies, has 5 voices, and was last updated by Profile photo of Dan Potter Dan Potter 11 months, 1 week ago.

  • Author
  • #31907
    Profile photo of Gary Seven
    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
    Profile photo of Curtis Smith
    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
    Profile photo of Gary Seven
    Gary Seven

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

  • #31929
    Profile photo of Paul Johnston
    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
    Profile photo of Gary Seven
    Gary Seven

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

  • #32025
    Profile photo of Mark

    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
    Profile photo of Dan Potter
    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.