Forum Discussion

Kayvault's avatar
Kayvault
Copper Contributor
Sep 20, 2023

Dynamic Distribution List creation that filters job titles

In theory this should be simple. But I am running into a few issues. I can either create the DDL but no members are returned, or I get a error when trying to use -contains -match. I will post the examples I have tried below. If there is a better way to use -match, -like, contains or any variation I am open to all suggestions. This seems like such a simple DDL but I am hitting a wall. Thank you. Also this is all Azure AD Cloud, nothing on premises. I have 5 users that have the term Clinical Director included in their title. I cant use EQ, because they all have various additions to their title. Example being "Chief Nursing officer / Clinical Director" My original thought was to use -contains but it fails to run everytime.

Example 1
New-DynamicDistributionGroup -Name "Hospice Clinical Directors Email" -RecipientFilter "(RecipientType -eq 'UserMailbox') -and (Title -like 'Clinical Director*')"

Example 1 will create the DDL but no membership is returned as shown below.

PS C:\Windows\system32> New-DynamicDistributionGroup -Name "Hospice Clinical Directors Email" -RecipientFilter "(RecipientType -eq 'UserMailbox') -and (Title -like 'Clinical Director*')"

Name ManagedBy
---- ---------
Hospice Clinical Directors Email

When searching for membership, no return.
PS C:\Windows\system32> # Get the DDL's RecipientFilter string
>> $filter = (Get-DynamicDistributionGroup -Identity "Hospice Clinical Directors Email").RecipientFilter
PS C:\Windows\system32> # Get recipients that match the DDL's RecipientFilter string | Show the name, title, and email address
>> Get-Recipient -RecipientPreviewFilter $filter | Select-Object Name,Title,PrimarySMTPAddress
PS C:\Windows\system32>




Example 2 will fail.
New-DynamicDistributionGroup -Name "Hospice Clinical Directors Email" -RecipientFilter "(RecipientType -eq 'UserMailbox') -and (Title -contains 'Clinical Director*')"

Error presented is
Write-ErrorMessage : Cannot process argument transformation on parameter 'RecipientFilter'. Cannot convert value "(RecipientType -eq 'UserMailbox') -and
(Title -contains 'Clinical Director*')" to type "System.String". Error: ""-contains" is not a valid operator. For a list of supported operators see the
command help.
"(RecipientType -eq 'UserMailbox') -and (Title -contains 'Clinical Director*')" at position 47."
At C:\Users\BenHodges\AppData\Local\Temp\tmpEXO_eyctuw4k.eqr\tmpEXO_eyctuw4k.eqr.psm1:1188 char:13
+ Write-ErrorMessage $ErrorObject
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-DynamicDistributionGroup], ParameterTransformationException
+ FullyQualifiedErrorId : [Server=SN6PR12MB2749,RequestId=fda8a7ea-e801-9606-be72-d1b6147f16c7,TimeStamp=Wed, 20 Sep 2023 17:05:08 GMT],Write-ErrorMessag
e




Thank you in advance for the help.

Ben


Resources