I need help with creating a AzureAD Group that collects all the users with Manager or Director in the job title, BUT NOT anyone with "Case Manager", "Lead Case Manager" or "Housing Manager" in the job title. I have tried everything can anyone help?
$groupName = "DynamicManagersGroup"
>> $groupDescription = "Dynamic Group for Managers"
>> $includedJobTitles = @("Manager", "Director")
>> $excludedJobTitles = @("Case Manager", "Lead Case Manager", "Housing Case Manager")
>>
>> $includedExpression = ($includedJobTitles | ForEach-Object { "[JobTitle] -contains '$_'" }) -join " -or "
>> $excludedExpression = ($excludedJobTitles | ForEach-Object { "[JobTitle] -contains '$_'" }) -join " -or "
>>
>> $dynamicMembershipRules = "(user." + $includedExpression + ") -and (-not (user." + $excludedExpression + "))"
>>
>> New-AzureADMSGroup -DisplayName $groupName -Description $groupDescription -MembershipRuleEvaluationType Dynamic -MembershipRuleFilterType Include -MembershipRule $dynamicMembershipRules
>>
New-AzureADMSGroup:
Line |
11 | … -Description $groupDescription -MembershipRuleEvaluationType Dynamic …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| A parameter cannot be found that matches parameter name 'MembershipRuleEvaluationType'
Here is the updated Powershell Script to add only if the Job Title matches
ManagerorDirectornot anyone withCase Manager,Lead Case ManagerorHousing Managerin the job title.Output:
After running the above script, if a user's job title matches Manager or Director, they will be automatically added to the group as shown below.