ADGroup Membership test working partially.

Welcome Forums General PowerShell Q&A ADGroup Membership test working partially.

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
3 years, 2 months ago.

  • Author
    Posts
  • #35184

    Participant
    Topics: 1
    Replies: 1
    Points: 1
    Rank: Member

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

  • #35185

    Participant
    Topics: 2
    Replies: 29
    Points: 0
    Rank: Member

    You should use {} not ""

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

  • #35187

    Participant
    Topics: 0
    Replies: 44
    Points: 43
    Rank: Member

    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.

  • #35245

    Participant
    Topics: 1
    Replies: 1
    Points: 1
    Rank: Member

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

The topic ‘ADGroup Membership test working partially.’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort