Solved

Get-Adgroupmember

Posted on 2016-09-14
11
55 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
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

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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