Forum Discussion
Dynamic Distribution List based on multiple AAD fields
- Jan 15, 2021
Cris20 Vasil prompted me to look at this request. This code worked for me...
$Filter = "((Title -like 'Architect') -and (ExchangeUserAccountControl -ne 'AccountDisabled'))"
New-DynamicDistributionGroup -Name "Architects" -DisplayName "System and Engineering Architects" -Alias AllArchitects -PrimarySmtpAddress Architects@Office365itpros.com -RecipientFilter $Filter
Set-DynamicDistributionGroup -Identity AllArchitects -ManagedBy Tony.Redmond -MailTip "Distribution List for anyone with Architect in the job title"
TR
Is this for Exchange Online? If so I'm afraid there is no good answer here, it depends on what exactly you mean by "block sign in" - is this the AzureAD BlockCredential attribute, or the Exchange-specific ones (AccountDisabled/ExchangeUserAccountControl/UserAccountControl). They do not always match in value, which poses a challenge here. Only one of these can actually be used for filtering though (UserAccountControl), so try that.
Other than that it's just stringing them together:
{(Title -eq "Job1" -or Title -eq "Job2") -and (UserAccountControl -eq "AccountDisabled, NormalAccount")}
- Cris20Jan 14, 2021Copper Contributor
Thank you for your answer!
This is indeed for Exchange Online.
The two fields I was referring to are from AzureAD User Profile, I don't know if Block sign in has a match in Exchange
I will try your suggestion.
Thanks again!