Getting AD Group Membership ADSI using PowerShell

后端 未结 1 615
夕颜
夕颜 2021-01-25 01:02

I currently have ADSI code to get the groups a user is a part of:

$searcher = [adsisearcher]\"(samaccountname=$env:USERNAME)\"
$searcher.FindOne().Properties.mem         


        
1条回答
  •  一向
    一向 (楼主)
    2021-01-25 02:01

    You already have both pieces, the first piece is finding the users in the group, the second piece is using the searcher to get properties for the users. Just use distinguishedname as the [adsisearcher] filter.

    $Group = [ADSI]"LDAP://cn=Test,cn=Test,dc=some,dc=domain,dc=net"
    $Group.Member | ForEach-Object {
        $Searcher = [adsisearcher]"(distinguishedname=$_)"
        $searcher.FindOne().Properties
    }
    

    0 讨论(0)
提交回复
热议问题