ChadKFranks
ChadKFranks

Reputation: 27

powershell to list multiple AD groups membership

I have a list of AD groups in a text files adgroups.txt:

Audit Internal_audit IT

I want to be able to have a CSV list:

Group Name Users

Nothing else. My poweshell script I am using is:

$groups = Get-Content c:\temp\ADGroups.txt

foreach($Group in $Groups) {            

Get-ADGroupMember -Id $Group | select  @{Expression={$Group};Label="Group Name"},* | Export-CSV c:\temp\GroupsInfo.CSV -NoTypeInformation

This spits out WAY to much info.

Group name Distinguished name Name Object Class etc......

Should I use a select-object and only select group name and name?

Upvotes: 1

Views: 14434

Answers (1)

TheMadTechnician
TheMadTechnician

Reputation: 36342

You almost had it! Replace the * with name and it should give you what you are looking for.

Get-ADGroupMember -Id $Group | select  @{Expression={$Group};Label="Group Name"},Name | Export-CSV c:\temp\GroupsInfo.CSV -NoTypeInformation -append

Upvotes: 1

Related Questions