How to create dynamic groups in azure ad through powershell?

Viewed 3211

I'm trying to create dynamic groups in azure ad using below powershell command:

New-AzureADMSGroup -DisplayName "us_demo_group" -Description "This group contains information of users from us domain" -MailEnabled $False -MailNickName "group" -SecurityEnabled $True -GroupTypes "DynamicMembership" -membershipRule "(user.department -contains ""Marketing"")" -membershipRuleProcessingState "On"

Reference link: https://docs.microsoft.com/en-us/powershell/module/azuread/new-azureadmsgroup?view=azureadps-2.

While executing this command I get below error :

> New-AzureADMSGroup : A parameter cannot be found that matches
> parameter name 'membershipRule'.

I have imported both the azureAD and azureADPrewview modules. I have global administartor role and Azure AD Premium P2 set up.

2 Answers

Ensure you're using the AzureADPreview and not the AzureAD.

In case you have both installed open a new powershell window and import the preview one like this:

Import-Module AzureADPreview

if you still getting the error then remove the AzureAD module first and then import azureADpreview

Remove-Module AzureAD -ErrorAction SilentlyContinue

Import-Module AzureADPreview
Related