Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

I need to find groups which have been nested within groups.

Posted on 2014-10-03
4
Medium Priority
?
161 Views
Last Modified: 2014-10-06
Hi,

Been trawling the web and I've managed to find many useful scripts but not one to find what I need.

I need a script to be able to specify a domain and then export all the groups it finds that have been nested within other groups, not users. Just the groups.

Is there a simple solution to be able to achieve this?

Cheers.
0
Comment
Question by:tegenius
[X]
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
  • 2
  • 2
4 Comments
 
LVL 41

Expert Comment

by:footech
ID: 40359864
For just the local domain, you can use this:
Get-ADGroup -filter * | Get-ADGroupMember | Where {$_.ObjectClass -eq "group"}

Open in new window

If you want to query a different server in another domain, you would likely have to add the -server parameter to the AD commands.  If you needed to use different credentials as well, I'd probably create a new PSDrive with the appropriate parameters, then change location into that (shown below) and then run the above code.
New-PSDrive -Name "trust" -PSProvider ActiveDirectory -Root "" -Credential (Get-Credential) -Server "dc01.temptrust.com"
cd trust:

Open in new window

0
 

Author Comment

by:tegenius
ID: 40361564
Thanks for replying :) This just displays all the groups in the domain.

What I need is something that displays a tree of groups that have been added as members of other groups... i.e. below we can see group 3 is nested in group 1 and group 1 is nested in group 4.

Group 1
> Group 3
Group 2
Group 3
Group 4
> Group 1

Cheers.
0
 
LVL 41

Accepted Solution

by:
footech earned 2000 total points
ID: 40361601
No, it doesn't show all groups in the domain.  You didn't specify that you need some special format.  Rather than a tree, here's another way of looking at it.
Get-ADGroup -filter * | % { $parent = $_.name; Get-ADGroupMember $_ | Where {$_.ObjectClass -eq "group"} | Select @{n="Parent";e={$parent}},Name }

Open in new window

0
 

Author Closing Comment

by:tegenius
ID: 40363386
Perfect :) Just what I needed.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

715 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