Use the Get-user command to find the group membership of a domain user
$ ((get-aduser wendy-properties *). Memberof-split (",") -replace "cn=", "" "
Extension 1: Get all users in group Wendy and Group Gaga
Get-aduser-Filter*-searchscope Subtree-searchbase"dc=xx,dc=xx,dc=xxx"-properties * | where {($ ($_. Memberof-split (",") | Select-string-simplematch "cn=")-replace"Cn=", "" ")-contains "GroupGaga" -or($($_. Memberof-split (",") | Select-string-simplematch "cn=")-replace"Cn=", "" ")-contains "GroupWendy"} | Select name,$ ($_. Memberof-split (",") | Select-string-simplematch "cn=")-replace"Cn=", "" ")
Extension 2: Define filter scope criteria to join a group of users who are not part of a group in this range
Get-aduser-Filter*-searchscope Subtree-searchbase"ou=xx,dc=xx,dc=xx,dc=xx"-properties * | where {$_. Title-eq "WW Ltd." -and $_. EmailAddress-ne $null -and $_. City-ne $null -and $_. Enabled-eq $true -and($($_. Memberof-split (",") | Select-string-simplematch "cn=")-replace"Cn=", "" ")-notcontains "groupnacy"} | Get-aduser |ForEach-object {add-adgroupmember-identity "groupnacy)"-members$_}
Extension 3: Querying users ' membership groups
$export[Email protected]()$Users=get-aduser-Filter*-searchscope Subtree-searchbase"ou=xx,ou=xx,dc=xx,dc=xx,dc=xx"-properties * foreach($user inch $users){#$User =get-aduser-identity wendy-properties *$members=($user. Memberof-split (",") | Select-string-simplematch "cn=")-replace"Cn=", " "$name=$user. Name#$all = $members | findstr/i "Groupwendy Groupgaga" can be placed in one condition$w=$members| findstr/i"Groupwendy" #filter groups, use findstr/i to ignore case parameters findstr/i "^groupgaga" means: query string starting with Groupgaga$g=$members| findstr/i"^groupgaga"$wendy=[string]$w$gaga=[string]$g$info=new-Object PsObject$info| Add-member-membertype noteproperty-name name-value$name$info| Add-member-membertype Noteproperty-name Groupgaga-value$gaga$info| Add-member-membertype Noteproperty-name Groupwendy-value$wendy$export+=$info}$CurrentDate= get-Date$CurrentDate=$CurrentDate. ToString (' yyyy-mm-DD ')$export| Export-csv D:\ps\userPermissioninfo_$CurrentDate. csv-encoding Utf8-notypeinformation
Powershell about Active Directory Group membership of a domain user