ADGroup Membership test working partially.

Attempting to AD User’s membership in specified group (true/False). Fails when attempting to run via pipeline. Works when split up in parts. Need another pair of eyes to review Failing code below.

# Working Code $GroupName = (Get-ADGroup "Domain Admins").DistinguishedName $User = get-aduser "Username" -Properties memberof $user.memberof -contains $GroupName

Failing code

get-aduser “Username” -Properties memberof | select name, @{n=“IsMember”; E="($_.memberof -contains {(Get-ADGroup ‘Domain Admins’).DistinguishedName})"}

You should use {} not “”

get-aduser “username” -Properties memberof | select name, @{n=“IsMember”; E={$_.memberof -contains (Get-ADGroup “Domain Admins”).DistinguishedName }}

Another way you could do it:

(Get-ADUser -Identity 'Username' -Properties memberOf).memberOf -contains (Get-ADGroup -Identity 'Domain Admins').DistinguishedName

This will just output true/false.

Thank you for your quick responses. Tested both ways, both worked great!