locked
To extract Users from group RRS feed

  • Question

  • HI 

    i have around 128 groups with DN, can any one help me with any script to extract the users from it.

    I got the samaccount name of the group and used below group and got direct users, can any anyone modify and help to get indirect users as well

    Import-Module ActiveDirectory
    cd AD:

    $MemberList = New-Item -Type file -Force “C:\GroupMembers15.csv”

    Import-Csv “C:\grps15.csv” | ForEach-Object {
    $GName = $_.SamaccountName
    $group = Get-ADGroup $GName
    $group.Name | Out-File $MemberList -Encoding Unicode -Append
    foreach ($member in Get-ADGroupMember $group) {$member.SamaccountName | Out-File $MemberList -Encoding Unicode -Append}
    $nl = [Environment]::NewLine | Out-File $MemberList -Encoding ASCII -Append
    }

    Thanks


    NA


    Wednesday, April 13, 2016 7:54 PM

Answers

  • The Get-ADGroupMember cmdlet's -Recursive parameter can retrieve members of nested groups.

    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Mike Laughlin Thursday, April 14, 2016 3:37 PM
    • Marked as answer by Bill_Stewart Monday, June 6, 2016 6:27 PM
    Thursday, April 14, 2016 2:25 PM

All replies

  • What exactly are you expecting the output to look like?

    What do you mean by "get indirect users as well"?


    -- Bill Stewart [Bill_Stewart]

    Wednesday, April 13, 2016 11:14 PM
  • Hello

    my expectation is to extract the users of a group and its nesting group all together

    the above script extract the users in parent group and not in nesting group


    NA

    Thursday, April 14, 2016 1:50 PM
  • The Get-ADGroupMember cmdlet's -Recursive parameter can retrieve members of nested groups.

    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Mike Laughlin Thursday, April 14, 2016 3:37 PM
    • Marked as answer by Bill_Stewart Monday, June 6, 2016 6:27 PM
    Thursday, April 14, 2016 2:25 PM
  • HELLO,

    Sounds good, however where should i add the -Recursive  in the above script.

    thanks


    NA

    Thursday, April 14, 2016 4:47 PM
  • Please read my previous reply.

    -- Bill Stewart [Bill_Stewart]

    Thursday, April 14, 2016 5:06 PM