Need to export users from AD group

I have a group that contains some users and group and query groups. I need to export the list of all of them and include the sub groups with the users and what sub groups they are a part of?  Does that make sense? :)

Thanks
rdefinoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FOXActive Directory/Exchange EngineerCommented:
Get-ADNestedGroupMembers -GroupName "thegroupname" | out-file -Filepath pathtoyourfile.txt
rdefinoAuthor Commented:
Get-ADNestedGroupMembers  isn't found in power shell. I did find a ps1 script called "Get-ADNestedGroupMembers.ps1". If this is used, how do I run it using your syntax?
Mark LoganCommented:
Try this

Get-ADGroupMember "Group name" | where objectclass -eq "user" | select-object name | out-file "c:\nested.txt"
$groups = Get-ADGroupMember "Group name" | where objectclass -eq "group"
foreach ($group in $groups) {
Get-ADGroupMember "$group" |  select-object name | out-file -Append "c:\nested.txt"
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

rdefinoAuthor Commented:
I tried "Get-ADGroupMember "Group name" | where objectclass -eq "user" | select-object name | out-file "c:\nested.txt""

and it just dumped the members, not the members of the nested groups.

How do I run:

$groups = Get-ADGroupMember BulkMail-PowerUsers | where objectclass -eq "group"
foreach ($group in $groups) {
Get-ADGroupMember "$group" |  select-object name | out-file -Append "c:\BulkMail-PowerUsers_nested.txt"
}


thanks
ZenVenkyArchitectCommented:
Easiest way is to use Net or DSQuery commands to do it.

net group “Group Name” /domain >> C:\memberlist.txt

dsquery group DC=consoto,DC=com -name groupname | dsget group -members >> C:\groupname.txt


dsquery group -name “Group Name” | dsget group -members >> C:\memberlist.txt
Mark LoganCommented:
Just paste the whole of the text into Powershell and press enter (after attributing your group name) and it will do it all of you.  The second portion of the script queries the groups that are nested within the parent group, and queries the members of them and outputs them to the same text file.
rdefinoAuthor Commented:
MArk,

Do I need to put the group name in where i see "group" ?

$groups = Get-ADGroupMember BulkMail-PowerUsers | where objectclass -eq "group"
foreach ($group in $groups) {
Get-ADGroupMember "$group" |  select-object name | out-file -Append "c:\BulkMail-PowerUsers_nested.txt"
}
Mark LoganCommented:
No, group defines the object type.  The only thing that you should substitute is "Group Name" and your file path if you choose
Mark LoganCommented:
Did that work in the end?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.