Report · 1 tool

Export nested group membership

Summary

Expands every nested group to list the real users who get access through a group, including the path they inherit it through. Essential before migrating groups or file share permissions.

Implementation

Choose your tool. Your choice is remembered on other samples.

ActiveDirectory module
Import-Module ActiveDirectory
function Expand-Group($group, $path) {
  foreach ($m in Get-ADGroupMember -Identity $group) {
    if ($m.objectClass -eq "group") { Expand-Group $m.DistinguishedName "$path > $($m.Name)" }
    else { [pscustomobject]@{ User = $m.SamAccountName; Name = $m.Name; Type = $m.objectClass; Via = $path } }
  }
}
$root = "Finance-Share-Modify"
Expand-Group $root $root | Sort-Object User -Unique |
  Export-Csv ".\$root-members.csv" -NoTypeInformation

Prerequisites

  • RSAT ActiveDirectory module

Output

CSV of users with the group they were found through.

Contributors

AuthorRole
Priyanshu UpadhyaySolution Architect, Microsoft 365 and Azure
Disclaimer. These samples are provided as is, without warranty of any kind. Read and test every script in a non-production tenant before you run it, and run reports before any command that changes or deletes data.