An Azure service that is used to automate, configure, and install updates across hybrid environments.
Hello Tyler Johnson, Thanks for the update, you can use the query below to process multiple files within a single folder to update the distribution list. Ensure that the target group name matches the file name.
# Connect to Exchange Online
Connect-ExchangeOnline -ManagedIdentity -Organization "<Your private Domain>"
# Define (Group, CSV) pairs
$FileLists = @(
@{ Group = "JohnsonTest2"; CsvPath = "C:\Test\JohnsonTest2.csv" },
@{ Group = "JohnsonTest3"; CsvPath = "C:\Test\JohnsonTest3.csv" }
)
foreach ($job in $FileLists) {
$targetGroup = $job.Group
$memberList = Import-Csv $job.CsvPath
# Get existing members for this group
$existingMembers = Get-DistributionGroupMember -Identity $targetGroup |
Select-Object -ExpandProperty PrimarySmtpAddress
foreach ($row in $memberList) {
if ($existingMembers -contains $row.UserEmail) {
Write-Output "$($row.UserEmail) is already a member of $targetGroup, skipping."
} else {
try {
Add-DistributionGroupMember -Identity $targetGroup -Member $row.UserEmail -ErrorAction Stop
Write-Output "Successfully added $($row.UserEmail) to $targetGroup"
} catch {
Write-Warning "Failed to add $($row.UserEmail) to $targetGroup: $($_.Exception.Message)"
}
}
}
}
Hope this helps. and please feel free to reach out if you encounter any issues. Thanks