Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

PowerShell find if a contact is a member of a AD group

$
0
0

Trying to find if an AD CONTACT is listed a member/object of an AD group. Can someone please guide me to what I’m missing in my script below? The script below works if the object is listed as a member, but fails if its listed as a contact. 

 

 

 

$users="Harris, Ella"

$Group ="#Yammer - Contractor Access"

$members = Get-ADGroupMember -Identity $group -Recursive | Select -ExpandProperty name

ForEach ($user in $users) {

    If ($members -contains $user) {

        Write-Host "$user in group"

    } Else {

        Write-Host "$user not in group"

    }

}

 

 

 

#$userDistinName = (get-aduser $user).distinguishedname

#cn=harris\, ella,ou=employees,ou=ohcin,dc=corp,dc=local


Viewing all articles
Browse latest Browse all 6937

Trending Articles