Filtering e-mail adresses from a group

Welcome Forums General PowerShell Q&A Filtering e-mail adresses from a group

This topic contains 4 replies, has 2 voices, and was last updated by

 
Participant
4 years, 3 months ago.

  • Author
    Posts
  • #18219

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 60
    Rank: Member

    Use -like instead of -contains

    So :

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

  • #18221

    Participant
    Points: 0
    Rank: Member

    Tried that, same problem.

    Thanks anyway.

  • #18224

    Participant
    Points: 60
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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.

The topic ‘Filtering e-mail adresses from a group’ is closed to new replies.