AlphaLolz
asked on
How can I get a list of all direct and indirect AD groups I'm a member of
I've reached the point after 20+ years in my company where I am now in so many AD groups and DL (both directly and indirectly) that I can no longer log on to the network or use some network resources (like IIS).
I'm looking for a powershell script (at least 2.x - prefer 4.x/5.x) that will list all the direct and indirect groups of which I'm a member in order to get removed from those which are useless.
I'm looking for a powershell script (at least 2.x - prefer 4.x/5.x) that will list all the direct and indirect groups of which I'm a member in order to get removed from those which are useless.
$username = 'YourUsername'
$dn = (Get-ADUser $username).DistinguishedName
Get-ADGroup -LDAPFilter ("(member:1.2.840.113556.1.4.1941:={0})" -f $dn) | select -expand Name | sort Name
You can do this in PowerShell
Import-Module ActiveDirectory
(Get-ADUser userName –Properties MemberOf | Select-Object MemberOf).MemberOf
Import-Module ActiveDirectory
(Get-ADUser userName –Properties MemberOf | Select-Object MemberOf).MemberOf
ASKER
The first answer is only giving me the groups I'm directly in, not indirectly. It won't include the the groups that the groups I'm in are in, etc., etc. up the entire tree.
ASKER
actually, it doesn't seem any of these recurse up the entire tree of groups for all the indirect group memberships.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
My mistake. Sorry. I'll have to give the first answer best and the second assisted since the way this place works is usually first answer that works wins, but they were both very close and useful.
Open in new window
To generate a csv file:Open in new window