已答复 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
     
      Has Code

    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
    }
    $Agg
    This 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
     
      Has Code

    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:

    http://social.technet.microsoft.com/Forums/en-US/exchangesvrgeneral/thread/19c6758d-0783-4a2c-bac0-2fb2b22d68c2/

  • 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
     
     Answered Has Code
    Get-DynamicDistributionGroup | % {
       Get-Recipient -RecipientPreviewFilter $_.RecipientFilter
    }

    or from a text file:

    import-csv "mycsv.csv" | Get-DynamicDistributionGroup -Identity $_.Name | % {
       Get-Recipient -RecipientPreviewFilter $_.RecipientFilter
    }

  • 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.



    • Edited by janeHHH Friday, May 11, 2012 7:28 PM
    • Edited by janeHHH Friday, May 11, 2012 7:29 PM
    •  
  • 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.


    ¯\_(ツ)_/¯


  • 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
     
     Proposed Answer

    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

    ¯\_(ツ)_/¯

  • 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.