Forum Discussion
TaranjeetSM11
Aug 11, 2023Copper Contributor
Dynamic Distribution Group with no Disabled Accounts
Hi
I'm trying to build a few Dynamic Distribution Lists in Exchange Online and want to only include Active Users (i.e., users that are marked "Active" in Azure AD). I've tried using the UserAccountControl attribute (-eq 514 or -ne 514 - both are returning the same results, which is strange), but it still includes user accounts that are disabled. This is how my recipient filter looks like:
RecipientType -eq 'UserMailbox' -and UserAccountControl -ne 514
What's the best way to achieve this in Exchange Online?
Thanks
Taranjeet Singh
- AnkidoIron Contributor
Hi TaranjeetSM11,
Yes, you can create a Dynamic Distribution Group in Exchange Online using PowerShell and exclude disabled accounts.Solution 1: In Exchange Online, use the AccountDisabled attribute in your filter rule. A disabled account in Entra ID will have AccountDisabled -eq $true
New-DynamicDistributionGroup -Name "ActiveUsersOnly" -RecipientFilter { (RecipientType -eq 'UserMailbox') -and (AccountDisabled -ne $true) }
Solution2: If AccountDisabled doesn’t work, you can filter based on UserPrincipalName, as disabled users sometimes lack a valid UPN.
New-DynamicDistributionGroup -Name "ActiveUsersOnly" -RecipientFilter { (RecipientType -eq 'UserMailbox') -and (UserPrincipalName -like '*@*') }
If you need any more help, feel free to reach out.
- TiberiaCopper Contributor
These dont work and throw an error that the filter syntax is invalid.
I dont understand Microsoft sometimes.- AnkidoIron Contributor
Hi Tiberia,
Sometimes the reasons could be:
- Authentication Issues
- Missing or Outdated Module
- Expired Session
- Insufficient Permissions
- Network Connectivity Issues
- Throttling or API Limits
Could you please provide the error message or share a screenshot?
- SajjadBrass Contributor
New-DynamicDistributionGroup -Name "ActiveUsersDDL" -RecipientFilter "((RecipientFilter -like "*") -and (UserAccountControl -band 2) -eq 0)" -RecipientContainer "OU=Users,DC=yourdomain,DC=com"
# Replace with your OU path - Try this:
{RecipientType -eq "UserMailbox" -and ExchangeUserAccountControl -ne "AccountDisabled"}- charles_thecyberguyCopper Contributor
unfortunately this doesn't work either.