msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

How do we create a new group with an assigned owner when using CBA

Open KirkMunro opened this issue 5 years ago • 1 comments

I'm trying to create groups using New-MgGroup. I have signed in using certificate-based authentication, so there is no concept of "me". I want the groups I create to have one or more specific owners.

This command, along with every alternative I have tried, fails:

New-MgGroup -DisplayName 'PSGraphTest' -MailNickname 'PSGraphTest' -MailEnabled:$false -SecurityEnabled -Owners @($user)

In that script, $user is assigned to a specific user that I retrieved with Get-MgUser. The error I get from that command is as follows:

New-MgGroup : A value without a type name was found and no expected type is available. When the model is specified, each value in the payload
must have a type which can be either specified in the payload, explicitly by the caller or implicitly inferred from the parent value.
At line:1 char:1
+ New-MgGroup -DisplayName 'PSGraphTest' -MailNickname 'PSGraphTest' -M ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: ({ body = Micros...oftGraphGroup }:<>f__AnonymousType1`1) [New-MgGroup_CreateExpanded1], RestEx
   ception`1
    + FullyQualifiedErrorId : Request_BadRequest,Microsoft.Graph.PowerShell.Cmdlets.NewMgGroup_CreateExpanded1

If I create the group without defining the owner, that works, but I should be able to do this in a single command. The error that is presented is not helpful, and documentation hasn't made it clear what I need to do either.

If someone could please tell me what is missing here, or accept this as a bug report if this should work (it seems like it should work from my perspective), then please respond with those details.

Thanks! AB#6804

KirkMunro avatar Nov 24 '20 15:11 KirkMunro

@KirkMunro, unfortunately this is one of those scenarios where the API exposes OData concepts, and we will need to add scenario based commands for these. https://docs.microsoft.com/en-us/graph/api/group-post-groups?view=graph-rest-1.0&tabs=http#example-2-create-a-group-with-owners-and-members

For now, this is how you can create a group with an owner in a single call.

$OwnersBinding = @{
    "[email protected]" = @("https://graph.microsoft.com/v1.0/users/$($User.Id)")
}

New-MgGroup -DisplayName 'PSGraphTest' `
            -MailNickname 'PSGraphTest' `
            -MailEnabled:$false `
            -SecurityEnabled `
            -AdditionalProperties $OwnersBinding

peombwa avatar Nov 25 '20 18:11 peombwa

Replaced by #1673. Feature will be reviewed as part of v3 milestone.

peombwa avatar Dec 10 '22 01:12 peombwa