circular nested groups across a forest

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Zikomo
Posts: 3
Last visit: Thu Jun 14, 2018 6:28 am

circular nested groups across a forest

Post by Zikomo »

OK, I am new to Powershell scripting but here is the problem that I have.
I need a script that will list all groups in the forest ( this is one forest with 3 domains) recursively and list all circular nested groups across the forest.
The current forest has +30000 groups. Nesting goes at least 5 levels deep and 1 group can have several hundreds of nested groups.

I started by filtering out all the groups that are top level groups and are not a member of any other group but then I got stuck.

Can someone put me on the right track how to go from here
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: circular nested groups across a forest

Post by jvierra »

Get-AdGroup -filter * -Server <global catalog server>:3268 -Recurse

This will get all groups in your forest recursively .
User avatar
Zikomo
Posts: 3
Last visit: Thu Jun 14, 2018 6:28 am

Re: circular nested groups across a forest

Post by Zikomo »

Hey Thnx for your answer but this does not seem correct:
So please correct me if I'm wrong

Get-adgroup does not support -recurse or -recursive
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: circular nested groups across a forest

Post by jvierra »

Sorry -typo:

Get-AdGroup -Filter * -Server <global catalog server>:3268 | Get-AdGroupMember -recurse

Then filter for groups.
User avatar
Zikomo
Posts: 3
Last visit: Thu Jun 14, 2018 6:28 am

Re: circular nested groups across a forest

Post by Zikomo »

Hey

The first part works fine but the part after the pipeline generates an error

[Get-ADGroupMember] , NotSupportedException
The operation is not supported on global catalog port
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: circular nested groups across a forest

Post by jvierra »

Then you will have to do it this way:
  1. Get-AdGroup -Filter * -Server sbs01:3268 |
  2.       ?{$_.objectclass -eq 'group'}|
  3.       %{Get-AdGroupMember $_.DistinguishedName -Recursive} |
  4.       ?{$_.objectclass -eq 'group'}
This topic is 7 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked