Solved

Get-Adgroupmember

Posted on 2016-09-14
11
62 Views
Last Modified: 2016-09-14
I will like to import a bulk  of AD groups, and get the all the members that are locating inside of it.  Can some provide me the correct syntax for this.  I will like to use the Foreach Cmdlt to do this work.
0
Comment
Question by:JCJohnson76
  • 6
  • 4
11 Comments
 
LVL 16

Expert Comment

by:FOX
ID: 41798281
List the names of your groups and at the top put a header named Groups and name it groups.csv

Import-Csv 'c:\filelocation\groups.csv' | Foreach{Get-ADGroupMember -identity $_.Groups -recursive | select name | Export-csv -path 'C:\filelocation\Groupmembers.csv' -NoTypeInformation
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41798282
Try..
Import-Module Activedirectory
Get-ADGroup -F * | %{$name = $_.Name; $_ | Get-ADGroupMember -Recursive | Select @{N="Group";E={$name}},@{N="Member";E={$_.Samaccountname}},ObjectClass} | Export-csv C:\Groupreport.csv -nti

Open in new window

Result will have all groups and it's members in CSV format. If you want to filter the members or groups from result that also can be done..
0
 

Author Comment

by:JCJohnson76
ID: 41798356
Import-Csv 'c:\filelocation\groups.csv' | Foreach{Get-ADGroupMember -identity $_.Groups -recursive | select name

This is only displaying the user list that is located in the groups.  I will like for it to display user list and the Group Name the user is located inside
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 40

Expert Comment

by:Subsun
ID: 41798376
@JCJohnson76, Did you check the code which I posted?
0
 

Author Comment

by:JCJohnson76
ID: 41798386
Subsun,

That code provide a broad scope of all groups.  The code I'm looking for is where I specify a range of  groups listed in a csv file.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41798402
You didn't mention, you need to read from a input file.. :-)
Try this modified code..
Import-Module Activedirectory
Import-csv C:\input.csv | %{$name = $_.GroupName; Get-ADGroupMember $_.GroupName -Recursive | Select @{N="Group";E={$name}},@{N="Member";E={$_.Samaccountname}},ObjectClass} | Export-csv C:\Groupreport.csv -nti

Open in new window


Sample input CSV
GroupName
GroupA
GroupB

Open in new window

0
 

Author Comment

by:JCJohnson76
ID: 41798429
And yes I populated the csv file with the correct header

Received a bunch of these errors

Get-ADGroupMember : Cannot validate argument on parameter 'Identity'. The argument is null or empty. Provide an argument that is not null
or empty, and then try the command again.
At line:2 char:78
+ Import-csv C:\csv\fin_groups.csv | %{$name = $_.GroupName; Get-ADGroupMember $_. ...
+                                                                              ~~~
    + CategoryInfo          : InvalidData: (:) [Get-ADGroupMember], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADGroupMember
0
 

Author Comment

by:JCJohnson76
ID: 41798435
Subsun
this is the code that i used which you provided

Import-Module Activedirectory
Import-csv C:\csv\fin_groups.csv | %{$name = $_.GroupName; Get-ADGroupMember $_.GroupName -Recursive | Select @{N="Group";E={$name}},@{N="Member";E={$_.Samaccountname}},ObjectClass} | Export-csv C:\csv\Groupreportt.csv -nti
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41798496
Get-ADGroupMember : Cannot validate argument on parameter 'Identity'. The argument is null or empty. Provide an argument that is not null
Means the input value is null, probably the input file has some trailing spaces..


Import-csv C:\input.csv | ?{$_.GroupName}|%{$name = $_.GroupName; Get-ADGroupMember $_.GroupName -Recursive | Select @{N="Group";E={$name}},@{N="Member";E={$_.Samaccountname}},ObjectClass} | Export-csv C:\Groupreport.csv -nti

Open in new window

0
 

Author Comment

by:JCJohnson76
ID: 41798546
Subsun,

Thanks, Horray,

Works like a charm
0
 

Author Closing Comment

by:JCJohnson76
ID: 41798547
Outstanding!!!!!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question