Lately I found out that the following doesn’t always work, I had problem with returning all users in a group.
|
1 |
Get-ADGroupMember -Recursive |
So I have created a small PowerShell function that basically does the same thing. Use it free of charge!
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
Function Get-ADNestedGroups { [cmdletbinding()] Param ( [Parameter(Mandatory=$true, HelpMessage="Please provide a valid identity.")]$Identity ) #Get all groups/users of the root group. $Members = Get-ADGroupMember -Identity $Identity; #Foreach member in the group. Foreach($Member in $Members) { #If the member is a group. If($Member.ObjectClass -eq "group") { #Run the function again against the group. $Users += Get-ADNestedGroups -Identity $Member.distinguishedName; } Else { #Add the user to the object array. $Users += @($Member); } } #Return the users Return ,$Users; } $Users = Get-ADNestedGroups -Identity "Domain Users"; |