Question: Good afternoon. So I have the below line of code that retrieves any AD group with the suffix of -blah1 and blah2. 

```
import-module activedirectory

$group = Get-ADGroup -Filter { (name -like "*-blah1") -or (name -like "*-blah2") } | Select Name

```

The above code shows groups:

> 
> abc-blah1  
> 
>  abc-blah2
> 
> 
> 

I want to be able to query these groups for a specific user (for example: `blahuser`). If the user does not exist in the group, I want to script to tell me. Any ideas? Thanks.

Answer: 
You are looking for [Get-ADGroupMember](https://learn.microsoft.com/en-us/powershell/module/addsadministration/get-adgroupmember) and a [Where-Object](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/where-object?view=powershell-5.1) command.

```
Get-ADGroup -Filter { (name -like "*-blah1") -or (name -like "*-blah2") } |
    Get-ADGroupMember |
    Where-Object {$_.SamAccountName -match 'blahuser'}

```
You can do it like this:

```
$userName = "ThisIsMyUserName"
$Groups = Get-ADGroup -Filter { (name -like "*-blah1") -or (name -like "*-blah2") } | Where-Object { $userName -notin ($_ | Get-ADGroupMember).SamAccountName} |select -ExpandProperty name

```