Link to home
Start Free TrialLog in
Avatar of rdefino
rdefinoFlag for United States of America

asked on

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
Avatar of FOX
FOX
Flag of United States of America image

Get-ADNestedGroupMembers -GroupName "thegroupname" | out-file -Filepath pathtoyourfile.txt
Avatar of rdefino

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Mark Logan
Mark Logan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rdefino

ASKER

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
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
Avatar of Mark Logan
Mark Logan

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.
Avatar of rdefino

ASKER

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"
}
No, group defines the object type.  The only thing that you should substitute is "Group Name" and your file path if you choose
Did that work in the end?