Author Posts

August 21, 2014 at 2:06 am

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?

August 21, 2014 at 2:12 am

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

August 21, 2014 at 2:13 am

Tried that, same problem.

Thanks anyway.

August 21, 2014 at 3:02 am

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?

August 21, 2014 at 6:15 am

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.