script to get members
-
Thursday, May 10, 2012 7:35 PM
Hi all,
Exchange 2010 SP1
I need to genetrate membership of all dynamic groups of Exchange 2010 and export each group to csv file.
I need group name, company, title, department of each group.
Now, I am generating them one by one.
Can anyone share?
Thank you.
All Replies
-
Thursday, May 10, 2012 7:44 PM
-
Thursday, May 10, 2012 8:44 PM
This needs to be run from the Exchange Management Shell and you also need to have the RSAT tools installed (for AD cmdlets).
Import-Module ActiveDirectory $Agg = @() Get-DistributionGroup | % { $temp = New-Object -TypeName PSObject $temp | Add-Member NoteProperty 'Name' $_.Name $temp | Add-Member NoteProperty 'DN' $_.distinguishedName $temp | Add-Member NoteProperty 'Members' (Get-ADGroupMember -Identity $_.DistinguishedName | Select-Object -ExpandProperty Name) $Agg += $temp } $AggThis provides back the group Name and DistinguishedName and the group members' Names. The group objects don't have a company, title, or department attribute. -
Thursday, May 10, 2012 8:49 PM
I don't believe that will get Exchnage 2010 Dynamic Groups.
¯\_(ツ)_/¯
-
Friday, May 11, 2012 11:15 AM
You are correct jrv. We rarely use them in our environment so I didn't distinguish between a dynamic and normal distro. Here is the proper way to do it:
$MarketingGroup = Get-DynamicDistributionGroup "Marketing Group" Get-Recipient -RecipientPreviewFilter $MarketingGroup.RecipientFilter -OrganizationalUnit $MarketingGroup.OrganizationalUnit
http://technet.microsoft.com/en-us/library/bb232019.aspx
or here's another (very similar way); but slightly different:
-
Friday, May 11, 2012 6:09 PM
Hi,
That's way I am using to generate one dynamic group at one time.
Just wonder if I have all dynamic groups in one csv file, can we generate all memberships based on this csv file at one time instead of generating one by one?
Thank you.
-
Friday, May 11, 2012 6:21 PM
Get-DynamicDistributionGroup | % { Get-Recipient -RecipientPreviewFilter $_.RecipientFilter }or from a text file:
import-csv "mycsv.csv" | Get-DynamicDistributionGroup -Identity $_.Name | % { Get-Recipient -RecipientPreviewFilter $_.RecipientFilter }- Edited by thepip3r Friday, May 11, 2012 6:23 PM
- Proposed As Answer by Richard MuellerMVP, Moderator Saturday, May 12, 2012 11:33 PM
- Marked As Answer by Bill_StewartMicrosoft Community Contributor, Moderator Friday, May 18, 2012 3:07 PM
-
Friday, May 11, 2012 6:38 PM
Hi,
That's way I am using to generate one dynamic group at one time.
Just wonder if I have all dynamic groups in one csv file, can we generate all memberships based on this csv file at one time instead of generating one by one?
Thank you.
Are you saying you want to vreate a distribution grou or you want to return all of the memners of a list of groups. You have to be lear about what you want. Your statements have all been very ambiguous.
¯\_(ツ)_/¯
-
Friday, May 11, 2012 7:28 PM
Hi jrv,
Sorry about the confusion.
>Are you saying you want to vreate a distribution grou or you want to return all of the memners of a list of groups.
I want to return all of members of a list of dynamic groups and also export each dynamic group members in csv format.
Thank you.
-
Friday, May 11, 2012 8:22 PM
Hi jrv,
Sorry about the confusion.
>Are you saying you want to vreate a distribution grou or you want to return all of the memners of a list of groups.
I want to return all of members of a list of dynamic groups and also export each dynamic group members in csv format.
Thank you.
What does your list of groups look like?
¯\_(ツ)_/¯
-
Friday, May 11, 2012 8:32 PM
>What does your list of groups look like?
name
Managers
Staff
IT
Finance
Billing
Marketing
Marketing Managers
..........
Thank you.
-
Friday, May 11, 2012 8:46 PM
If that is what you have then thePip3r posted a solution. Just use that.
¯\_(ツ)_/¯
- Edited by jrvMicrosoft Community Contributor Friday, May 11, 2012 8:48 PM
-
Tuesday, May 15, 2012 2:26 PM
Thank you for your help.
Can we also add the above script to output each dynamic group membership result in the csv file automatically?
Thanks a lot.
-
Tuesday, May 15, 2012 3:03 PM
Thank you for your help.
Can we also add the above script to output each dynamic group membership result in the csv file automatically?
Thanks a lot.
Get-DynamicDistributionGroup | % {
Get-Recipient -RecipientPreviewFilter $_.RecipientFilter
} | Export-Csv file.csv -notype¯\_(ツ)_/¯
- Proposed As Answer by Richard MuellerMVP, Moderator Tuesday, May 15, 2012 3:30 PM
-
Tuesday, May 15, 2012 3:59 PM
Hi jrv,
Thank you and this is for one dynamic group output.
If I use csv file with 200 dynamic groups inside, can we also generating each output for each dynamic group at once instead of getting each output manually?
import-csv "mycsv.csv" | Get-DynamicDistributionGroup -Identity $_.Name | % {
Get-Recipient -RecipientPreviewFilter $_.RecipientFilter
}Thank you.

