Powershell about Active Directory Group membership of a domain user

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.