DLs export

Glenn Maxwell 10,186 Reputation points
2021-01-22T21:10:57.49+00:00

Hi All

I have users list in a csv file in the below format. i want to pull all the DLs and unified groups these users are members of. How can i export this information to a csv file. experts guide me on this.

users
user1@Company portal .com
user2@Company portal .com

Microsoft Office Online Server
Microsoft Office Online Server
Microsoft on-premises server product that runs Office Online. Previously known as Office Web Apps Server.
592 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,240 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,386 questions
{count} votes

Accepted answer
  1. Eric Yin-MSFT 4,386 Reputation points
    2021-01-25T08:10:08.567+00:00

    Hi,
    Assuming you have a csv/txt file like this:

    name  
    user1  
    user2  
    administrator  
    

    Run the following script in EMS:

     $names= Import-Csv c:\temp\name.csv  
     $Result= @()   
     $groups= Get-DistributionGroup  
     foreach ($name in $names) {  
     foreach($group in $groups){  
     $members= Get-DistributionGroupmember $group  
     foreach ($member in $members){  
     if ($member.name -eq $name.name){  
     $Result1 = New-Object PSObject   
     $Result1 | Add-Member NoteProperty -Name "User" -Value $name.name  
     $Result1 | Add-Member NoteProperty -Name "group" -Value $group  
     $Result += $Result1  
     }}}}  
     $Result|Export-csv -Path c:\temp\result.csv -NoTypeInformation  
    

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Ashok M 6,506 Reputation points
    2021-01-24T12:37:53.2+00:00

    Hi @Glenn Maxwell ,

    Please refer the below link for the similar query,

    https://learn.microsoft.com/en-us/answers/questions/105946/user-access-to-distribution-lists-and-unified-grou.html

    If the above suggestion helps, please click on "Accept Answer" and upvote it.

    0 comments No comments

  2. Glenn Maxwell 10,186 Reputation points
    2021-01-25T14:51:28.58+00:00

    i am using exchange hybrid environment, i have few DLs in onprem and few DLs in cloud, when i use this syntax in cloud i am getting error.

    WARNING: The object DL1 has been corrupted or isn't compatible with Microsoft support
    requirements, and it's in an inconsistent state. The following validation errors happened:
    WARNING: The group "DL1" is not managed by any recipient but the MemberJoinRestriction
    property is set to "ApprovalRequired".

    Cannot process argument transformation on parameter 'Identity'. Cannot convert the "DL2" value of type
    "Deserialized.Microsoft.Exchange.Data.Directory.Management.DistributionGroup" to type
    "Microsoft.Exchange.Configuration.Tasks.DistributionGroupMemberIdParameter".

    • CategoryInfo : InvalidData: (:) [Get-DistributionGroupMember], ParameterBindin...mationException
    • FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-DistributionGroupMember
    • PSComputerName : outlook.office365.com

    How can i export unified groups for the users


  3. Glenn Maxwell 10,186 Reputation points
    2021-01-27T18:45:51.617+00:00

    i am getting the below warning, i have also used the below syntax.

    $Result | -Result size Unlimited Export-csv -Path c:\temp\result.csv -NoTypeInformation

    WARNING: By default, only the first 1000 items are returned. Use the ResultSize parameter to specify the number of
    items returned. To return all items, specify "-ResultSize Unlimited". Be aware that, depending on the actual number of
    items, returning all items can take a long time and consume a large amount of memory. Also, we don't recommend storing
    the results in a variable. Instead, pipe the results to another task or script to perform batch changes.

    $names= Import-Csv c:\temp\name.csv
    $Result= @()
    $groups= Get-DistributionGroup
    foreach ($name in $names) {
    foreach($group in $groups){
    $members= Get-DistributionGroupmember -ResultSize Unlimited $group
    foreach ($member in $members){
    if ($member.name -eq $name.name){
    $Result1 = New-Object PSObject
    $Result1 | Add-Member NoteProperty -Name "User" -Value $name.name
    $Result1 | Add-Member NoteProperty -Name "group" -Value $group
    $Result += $Result1
    }}}}
    $Result|Export-csv -Path c:\temp\result.csv -NoTypeInformation

    Will the above script work in Exchange Online