azure-ad-powershell-v2

Invalid value specified for property 'groupTypes' of resource 'Group'


I am new to Azure and I am trying to create a dynamic Azure Ad group through PowerShell by following below cmdlet:

New-AzureADMSGroup -DisplayName "GroupName" -Description "Des" -MailEnabled $False -MailNickname "Mail" -SecurityEnabled $True  -GroupTypes "Dynamic"

But I am getting the below error:

New-AzureADMSGroup : Error occurred while executing NewMSGroup
Code: Request_BadRequest
Message: Invalid value specified for property 'groupTypes' of resource 'Group'.
InnerError:
  RequestId: 419e641b-a15a-4417-840c-ce30a3541d8d
  DateTimeStamp: Wed, 15 Jun 2022 05:25:33 GMT
HttpStatusCode: BadRequest
HttpStatusDescription: Bad Request
HttpResponseStatus: Completed
At line:1 char:1
+ New-AzureADMSGroup -DisplayName "Testgroup1" -Description "Group assi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-AzureADMSGroup], ApiException
    + FullyQualifiedErrorId : Microsoft.Open.MSGraphBeta.Client.ApiException,Microsoft.Open.MSGraphBeta.PowerShell.NewMSGroup

I am following this Microsoft Document:

New-AzureADMSGroup (AzureAD) | Microsoft Docs

I tried to modify the command like below:

New-AzureADMSGroup -DisplayName "GroupName" -Description "Des" -MailEnabled $False -MailNickname "Mail" -SecurityEnabled $True  -GroupTypes "DynamicGroup"

But it did not work. I am still getting the same error.

How to create dynamic Azure Ad group? Did anyone face the same issue?


Solution

  • I tried to reproduce the same in my environment and I am able to create dynamic group successfully like below:

    To create Dynamic group, make use of below PowerShell script:

    New-AzureADMSGroup -DisplayName "RukminiGroup" -Description "Dynamic group" -MailEnabled $False -MailNickName "Ruk" -SecurityEnabled $True -GroupTypes "DynamicMembership" -MembershipRule "(user.department -contains ""IT"")" -MembershipRuleProcessingState "On"
    

    By executing the above script, the Dynamic group created successfully like below:

    enter image description here

    enter image description here

    Reference:

    Azure AD Group Membership PowerShell - Azure Lessons by Bijay Kumar.