Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell AzureAD Script to change Groups from Static to Dynamic

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?

like image 695
JaviHavi Avatar asked Dec 13 '25 02:12

JaviHavi


1 Answers

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

like image 183
Cpt.Whale Avatar answered Dec 15 '25 17:12

Cpt.Whale



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!