An Azure service that is used to automate, configure, and install updates across hybrid environments.
Hello Tyler Johnson, To remove the Parents from the Existing distribution group you can use the Remove-DistributionGroupMember, this will remove the parent from the existing group. For example.
# 1. Connect to Exchange Online (Managed Identity)
Connect-ExchangeOnline -ManagedIdentity -Organization "<Your Private Domain>"
# 2. Define target Distribution Group identity
$targetGroup = "Brown Parents"
# 3. Import members from CSV (current class list)
$memberList = Import-Csv "C:\Users\tylejohn\OneDrive - Alcuin School\Documents\Power Automate Lists\Brown.csv"
# 4. Build a list of desired email addresses from the CSV
$desiredMembers = $memberList.UserEmail
# 5. Fetch current members (email addresses) in the DG
$existingMembers = Get-DistributionGroupMember -Identity $targetGroup |
Select-Object -ExpandProperty PrimarySmtpAddress
# 6. ADD: members that are in CSV but not yet in the group
foreach ($email in $desiredMembers) {
if ($existingMembers -contains $email) {
Write-Output "${email} is already a member of $targetGroup, skipping add."
} else {
try {
Add-DistributionGroupMember -Identity $targetGroup -Member $email -ErrorAction Stop
Write-Output "Successfully added ${email} to $targetGroup"
} catch {
Write-Warning "Failed to add ${email}: $($_.Exception.Message)"
}
}
}
# 7. REMOVE: members that are in the group but not in the CSV
foreach ($email in $existingMembers) {
if ($desiredMembers -notcontains $email) {
try {
Remove-DistributionGroupMember -Identity $targetGroup -Member $email -Confirm:$false -ErrorAction Stop
Write-Output "Removed ${email} from $targetGroup because it is no longer in the class list."
} catch {
Write-Warning "Failed to remove ${email}: $($_.Exception.Message)"
}
}
}
Hope this helps! please let us know if you face any difficulties, thanks