Filtering e-mail adresses from a group

This topic contains 4 replies, has 2 voices, and was last updated by  Matt Walker 3 years, 9 months ago.

  • Author
  • #18219

    Matt Walker

    Hi All,

    I'm currently trying to run a one-liner to filter out a list of users with a particular e-mail address from a secuirty group in AD but i'm not having much success.

    The script i've got so far is as follows...


    Get-ADGroupMember -Identity "CN=The Group,OU=The OU,DC=The DC" | Get-ADUser | Where-Object {$_.UserPrincipalName -contains "*emailaddress"}


    When I run that, PowerShell doesn't error it just acts as if it's done something but produces no data, once I do get this to work I then plan to export it but obviously I need this bit to work first, can anyone put me out of my misery please?

  • #18220

    Tim Pringle

    Use [i]-like[/i] instead of [i]-contains[/i]

    So :

    Get-ADGroupMember -Identity "CN=The Group,OU=The OU,DC=The DC" | Get-ADUser | Where-Object {$_.UserPrincipalName -like "*emailaddress"}

  • #18221

    Matt Walker

    Tried that, same problem.

    Thanks anyway.

  • #18224

    Tim Pringle

    It's a strange one, worked fine on my system after i did that.

    Only thing i can think off, do your UPN's definately match your email addresses? Any reason you're not querying the emailaddress attribute?

  • #18242

    Matt Walker

    Nevermind it's me being an idiot, it works perfectly.

    I did a test using an e-mail address I know is defintely within the group and it returned back as I expected so it means the e-mail addresses i'm looking for within the group don't exist!

    Thanks for all your help.

You must be logged in to reply to this topic.