Forum Discussion
Kayvault
Sep 20, 2023Copper Contributor
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
https://learn.microsoft.com/en-us/powershell/exchange/recipientfilter-properties?view=exchange-ps
Text string properties that accept wildcard characters require the -like operator (for example, "Property -like 'abc*'"). In Exchange Online PowerShell, you can't use the wildcard as a prefix (for example, "Property -like '*abc'") is not allowed).
Include the hyphen before all logical or comparison operators. The most common operators include:
-and
-or
-not
-eq (equals)
-ne (not equal)
-lt (less than)
-gt (greater than)
-like (string comparison)
-notlike (string comparison)
- Dhruva_KudvaBrass Contributor
Hi Kayvault - Looks like in cloud-based environments, you can't use a wildcard as the first character. For example, 'Sales*' is allowed, but '*Sales' isn't allowed.
https://learn.microsoft.com/en-us/powershell/module/exchange/set-dynamicdistributiongroup?view=exchange-ps#-recipientfilter
An alternative would be to assign a customattribute value to the 5 users and use that in your filter instead of the Title.
Regards
Dhruva
- Andres-BohrenSteel Contributor
https://learn.microsoft.com/en-us/powershell/exchange/recipientfilter-properties?view=exchange-ps
Text string properties that accept wildcard characters require the -like operator (for example, "Property -like 'abc*'"). In Exchange Online PowerShell, you can't use the wildcard as a prefix (for example, "Property -like '*abc'") is not allowed).
Include the hyphen before all logical or comparison operators. The most common operators include:
-and
-or
-not
-eq (equals)
-ne (not equal)
-lt (less than)
-gt (greater than)
-like (string comparison)
-notlike (string comparison)
- Andres-BohrenSteel ContributorHi Kayvault
Get-User -Identity m.muster | fl Title
Title : Sales Manager
Filterable properties for the RecipientFilter parameter on Exchange cmdlets
https://learn.microsoft.com/en-us/powershell/exchange/recipientfilter-properties?view=exchange-ps
Get-Recipient -RecipientPreviewFilter "(RecipientTypeDetails -eq 'UserMailbox') -and (Title -eq 'Sales Manager')"
Name RecipientType
---- -------------
Muster, Max UserMailbox
If you get the required result you can create the DynamicDistributionGroup.
Regards
Andres