Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get Groups from AD Accounts and the nested groups

Posted on 2016-09-22
3
Medium Priority
?
73 Views
Last Modified: 2016-09-28
Hi EE

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 ..

Account1
MemberOF:
Group1
--Group1 is nested in Group2
--Group2 is nested in Group3
--Group3 is nested in Group4
0
Comment
Question by:MilesLogan
3 Comments
 
LVL 12

Expert Comment

by:Gary Dewrell
ID: 41811371
0
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 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

0
 
LVL 2

Author Closing Comment

by:MilesLogan
ID: 41820123
thank you Subsun1
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

How to deal with a specific error when using the Enable-RemoteMailbox cmdlet to create a mailbox in the cloud-based service, for an existing user in an on-premises Active Directory.
Wouldn't it be nice if objects in Active Directory automatically moved into the correct Organizational Units? This is what AutoAD aims to do and as a plus, it automatically creates Sites, Subnets, and Organizational Units.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

927 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