Forum Discussion
Diego13
Nov 09, 2022Copper Contributor
Get nested AD groups from bulk user or OU
Hi, I would like to export in a csv file all groups and nested groups from bulk AD user or OU. Example: Users Groups NestedGroups User1 Group1 NestedGroup1 ...
Alan2022
Nov 10, 2022Iron Contributor
# Filter Groups in AD based on OU
$searchBase = "OU=Test,DC=company,DC=com"
Get-ADGroup -Filter * -SearchBase $searchBase -Property * | Sort-Object Name
# Get List of Members base on Group Name
Get-ADGroupMember -Identity '<GroupName>' -Recursive | Select-Object -Property @{n="Members"; e={ $_.Name }} | Sort-Object Members
- Diego13Nov 10, 2022Copper ContributorHi Alan, thanks for the powershell provided.
Is it possible to export the results as requested please ?- Alan2022Nov 11, 2022Iron Contributor
Diego13
Hi,Yes you can just save them in a variable like $result. Then use export to csv ps script.
$result | Export-Csv c:\temp\test.csv -NoTypeInformation- Diego13Nov 11, 2022Copper ContributorHi,
I have this error now when adding "$result | Export-Csv c:\temp\test.csv -NoTypeInformation" at the end of the script:
Get-ADGroupMember : Cannot find an object with identity: 'GroupName' under: 'DC=...'