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 ...
Diego13
Nov 14, 2022Copper Contributor
Hi,
I found this script who works well and the results are exactly what I need but I cannot export it in csv file because of "Tree view":
http://vcloud-lab.com/entries/active-directory/powershell-active-directory-show-treeview-of-user-or-group-memberof-hierarchy
Any idea to transform the output in csv file please ?
I found this script who works well and the results are exactly what I need but I cannot export it in csv file because of "Tree view":
http://vcloud-lab.com/entries/active-directory/powershell-active-directory-show-treeview-of-user-or-group-memberof-hierarchy
Any idea to transform the output in csv file please ?
Alan2022
Nov 14, 2022Iron Contributor
This one will get all the group in OU & its list of members.
# Create Array
$customObject = $null
$reports = @()
# Generate CSV Filename
$file = "$($env:USERPROFILE)\Desktop\ADGroups.csv"
if (Test-Path $file) {
Remove-Item $file
}
# Filter Groups in AD based on OU
$searchBase = "OU=test,DC=domain,DC=com" # <-Change the searchbase base on your OU Location
$resultGroups = Get-ADGroup -Filter * -SearchBase $searchBase -Property * | Sort-Object Name
ForEach($resultGroup in $resultGroups){
# Get List of Members base on Group Name
Get-ADGroupMember -Identity $resultGroup.DistinguishedName -Recursive | Select-Object -Property @{n="Members"; e={ $_.Name }} | Sort-Object Members | ForEach-Object {
# Create a Custom Object
$customObject = [PSCustomObject]@{
GroupName = $resultGroup.Name
Members = $_.Members
}
$reports += $customObject
}
}
# Export result to csv
$reports | Export-Csv $file -NoTypeInformation
Write-Host "Finished..."