user3290171
user3290171

Reputation: 131

Powershell - Nested Recursive Groups

I have a script that currently grabs all the members of the domain admins group. If there are any nested groups it puts all the members of these in to a list in a CSV.

Get-ADGroupMember -identity “Domain Admins” -recursive | select name | Export-csv -path C:\Output\Groupmembers.csv -NoTypeInformation

How do I get this it to display the name of the group the user was nested in beside their name in the CSV?

This would then show the users name and what group they were nested in.

Upvotes: 1

Views: 1578

Answers (1)

Yallabina
Yallabina

Reputation: 117

I know the post is old but I found the function that someone already created a to get nested groups and list the nested group name as you requested. there are different way to ran the function but I saved the script as a function and I imported when using import-module "C:\location of the modulegoeshere\PSM1"Please find the link for the script below, I saved script as a module and imported. so you code should look like this

import-csv "C:\temp\get-ADNestedGroupMembers

Get-ADGroup "MyGroup" | Get-ADNestedGroupMembers | select name, nested

https://gallery.technet.microsoft.com/scriptcenter/Get-nested-group-15f725f2.

Upvotes: 1

Related Questions