Get Groups from AD Accounts and the nested groups

Posted on 2016-09-22
Last Modified: 2016-09-28

Does anyone have a script that will export to cvs all the groups an AD account is a member of ?

but not just direct groups , also the groups that those groups are nested in ..

--Group1 is nested in Group2
--Group2 is nested in Group3
--Group3 is nested in Group4
Question by:MilesLogan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 12

Expert Comment

by:Gary Dewrell
ID: 41811371
LVL 40

Accepted Solution

Subsun earned 500 total points
ID: 41811588
Try this and see if it works for you...
Function Get-Nested ($User){
    Get-ADPrincipalGroupMembership $User | % {
      $_ | Select Name,@{N="ChildGroup";E={$Group.Samaccountname}};$Group = $_
      Get-Nested $_.Name  | Select Name,@{N="ChildGroup";E={$Group.Samaccountname}}

Get-Nested UserA | Select * -Unique

Open in new window


Author Closing Comment

ID: 41820123
thank you Subsun1

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question