Filtering e-mail adresses from a group

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

  • Author
    Posts
  • #18219
    Profile photo of Matt Walker
    Matt Walker
    Participant

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

    [blockquote]

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

    [/blockquote]

    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
    Profile photo of Tim Pringle
    Tim Pringle
    Participant

    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
    Profile photo of Matt Walker
    Matt Walker
    Participant

    Tried that, same problem.

    Thanks anyway.

  • #18224
    Profile photo of Tim Pringle
    Tim Pringle
    Participant

    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
    Profile photo of Matt Walker
    Matt Walker
    Participant

    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.