Trying to change some Azure AD Groups from Static to Dynamic via powershell (there are 75 groups so we need to do this somwhow)
originally i was trying to run it automatized from a list in TXT with this script:
$grouplist = Get-Content -Path "C:\foldername\filename.txt"
Set-AzureADMSGroup -DisplayName $group -GroupTypes "DynamicMembership" -membershipRule "(user.department -eq "$group") and (user.jobTitle -eq "JobtitleXX")"
$counter += 1
if($counter -eq 1){
Sleep -Seconds (60 * 1)
$counter = 0
}
}
It fails.
So i tried it as a simple-single group script:
Set-AzureADMSGroup -Id XXXXXXXXXXXXXXXXXXXXXXXXXXXX -GroupTypes "DynamicMembership" -MembershipRule '(user.department -eq "DepartmentXX") and (user.jobTitle -eq "JobTitleXX")' -MembershipRuleProcessingState "On"
But it is failing with this error:
Set-AzureADMSGroup : A parameter cannot be found that matches parameter name 'MembershipRule'.
At line:1 char:93
+ ... -102d855d224c -GroupTypes "DynamicMembership" -MembershipRule '(user. ...
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-AzureADMSGroup], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.Open.MSGraphV10.PowerShell.SetMSGroup
After a few tries nothing seems to work. Could anyone help me out?
For some reason, the -MembershipRule parameter on Set-AzureADMSGroup is still only available in the preview release of the AzureAD module.
# Install the preview module. May need to -AllowClobber
Install-Module AzureADPreview
# Import it into scripts instead of AzureAD. May need to -Force if AzureAD is loaded
Import-Module AzureADPreview
Get-Command Set-AzureADMSGroup | Select -ExpandProperty Parameters
Key
---
GroupTypes
MembershipRule # voila!
MembershipRuleProcessingState
As of the current version of AzureAD: 2.0.2.130
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With