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 ago.

  • Author
    Posts
  • #31907

    Gary Seven
    Participant

    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?

  • #31908

    Curtis Smith
    Participant

    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.

  • #31928

    Gary Seven
    Participant

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

  • #31929

    Paul Johnston
    Participant

    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.

  • #32014

    Gary Seven
    Participant

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

  • #32025

    Mark
    Participant

    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
    Participant

    The mail attribute doesn't necessarily match proxyaddresses.

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

You must be logged in to reply to this topic.