A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
Did you mean you would like to add members to the distribution list using their email addresses, while you have some inaccurate information in the csv file.
For example, user1@Company portal .com no longer exists in your organization, but it is still in the csv file.
If I misunderstood your question, please feel free to correct me.
In this case, I suppose you may follow these steps:
1.Add the members to the distribution list
Import-CSV add_members.csv | ForEach {Add-DistributionGroupMember -Identity "DG1" -Member $_.PrimarySmtpAddress}
The add_members.csv file is like:
PrimarySmtpAddress
user01@Company portal .com
user02@Company portal .com
2.Get the PrimarySmtpAddress value of the current members of the distribution list and export to a csv file named current_members.csv
Get-DistributionGroupMember -Identity ******@contoso.com | select-object PrimarySmtpAddress | export-csv current_members.csv
The current_members.csv file would be like:
TYPE Selected.Microsoft.Exchange.Data.Directory.Management.ReducedRecipient
"PrimarySmtpAddress"
"user01@Company portal .com"
"user02@Company portal .com"
3.Use a Powershell script to compare the two csv files and export the results to a csv file named failed.csv (you need to run the script in Powershell instead of EMS)
$file1 = import-csv -Path "C:\temp\add_members.csv"
$file2 = import-csv -Path "C:\temp\current_members.csv"
Compare-Object $file1 $file2 -property PrimarySmtpAddress | select PrimarySmtpAddress | Export-Csv -Path "C:\temp\failed.csv"
You may check the failed.csv file to see the difference between the two csv files, which means users failed to be added.
If the response 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.