Recommended Solution: Use Power Automate + Azure Automation + Exchange Online PowerShell
Step-by-Step Setup
1. Create an Azure Automation Account
If not already created:
Go to Azure Portal → Automation Accounts → Create
2. Import ExchangeOnlineManagement Module
In your Automation Account:
Go to Modules → Browse Gallery
Search for ExchangeOnlineManagement
Import it
3. Create a Runbook (PowerShell)
In the Automation Account:
Go to Runbooks → Create a Runbook
Name: RemoveUserFromDLs
Type: PowerShell
Paste the script below
PowerShell Script for Runbook:
param (
[string]$UserPrincipalName
)
# Connect to Exchange Online
Connect-ExchangeOnline -ManagedIdentity
# Get all distribution groups the user is a member of
$DLs = Get-DistributionGroup | Where-Object {
Get-DistributionGroupMember -Identity $_.Identity -ResultSize Unlimited | Where-Object {$_.PrimarySmtpAddress -eq $UserPrincipalName}
}
# Remove user from each DL
foreach ($dl in $DLs) {
Remove-DistributionGroupMember -Identity $dl.Identity -Member $UserPrincipalName -Confirm:$false
}
Important: You can also use certificate-based authentication or managed identity instead of prompting for credentials.
4. Trigger the Runbook from Power Automate
In Power Automate:
Use "Create job" action from Azure Automation
Resource Group
Automation Account
Runbook Name: RemoveUserFromDLs
Parameters:
{
"UserPrincipalName": "user@domain.com"
}
If I have answered your question, please mark it as the preferred solution ✅ . If you like my response, please give it a Thumbs Up 👍.
Regards,
Riyaz