Filtering e-mail adresses from a group

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?

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"}

Tried that, same problem.

Thanks anyway.

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?

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.