powershellazure-active-directorymicrosoft-teamsazure-ad-powershell-v2

Create Teams-room with DynamicMembership using PowerShell module


I want to create a new team in Microsoft Teams with dynamic membership using powershell using the modules MicrosoftTeams and AzureADPreview

I can create a new team using the command

New-Team -DisplayName "NewTeam" -Description "New Team" -MailNickName "NewTeam" -Visibility "Private"

When I try to set the group type to Dynamic Memberehip with the command,

Set-AzureADMSGroup -Id "xxx" -GroupTypes "DynamicMembership" -MembershipRuleProcessingState "On" -MembershipRule "user.mailNickname -eq ""yyy"""

I get the following error message:

Set-AzureADMSGroup : Error occurred while executing SetMSGroup
Code: Request_BadRequest
Message: One or more properties contains invalid values.
InnerError:
  RequestId: e82c8ab7-c0a1-4631-b983-fc5cb2b0e860
  DateTimeStamp: Mon, 06 Jul 2020 12:13:37 GMT
HttpStatusCode: BadRequest
HttpStatusDescription: Bad Request
HttpResponseStatus: Completed
At line:1 char:1
+ Set-AzureADMSGroup -ID "db9e3933-1883-4d3a-88fe-f95d29b5d8c6" -Securi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-AzureADMSGroup], ApiException
    + FullyQualifiedErrorId : Microsoft.Open.MSGraphBeta.Client.ApiException,Microsoft.Open.MSGraphBeta.PowerShell.SetMSGroup

Solution

  • Had excatly the same issue, and a hard time to figure this one out as MS Docs are just a piece of crap. So, the culprit is acutally not the membership rule, this one is fine, though everything points into it's direction. But in reality, its all about the "GroupType" which seem to be wrong in the MS Docs.

    So this is the correct command to convert an Unified Static Group to a Dynamic one:

    Set-AzureAdMsGroup -ID xxxx -GroupTypes @("DynamicMembership", "Unified") -MembershipRuleProcessingState "On" -MembershipRule "(user.mailNickname -eq ""yyyy"")"