Skip to content

New-MgTeam cmdlet does not work #119

Closed

Description

@bchap1n

I am able to create new Teams using the Graph Explorer:

POST: https://graph.microsoft.com/beta/Teams {"template@odata.bind":"https://graph.microsoft.com/beta/teamsTemplates('standard')","displayName":"waffleSloth4","description":"waffleSloth4"}

but when I try the same with 'New-mgTeam' it fails:

Connect-Graph -Scopes "Group.ReadWrite.All"

$body = @"
{
    "template@odata.bind":"https://graph.microsoft.com/beta/teamsTemplates('standard')",
    "displayName":"waffleSloth4",
    "description":"waffleSloth4"
}
"@

New-mgTeam -BodyParameter $body

error message:
The navigation bind for template was missing in request.

Activity

  1. added this to the 0.5.0 milestone on Mar 26, 2020
  2. peombwa commented on Apr 1, 2020

    @peombwa
    Member

    brock chapin (@bchap1n) As part of #87, we will be introducing an AdditionalProperties bag that will allow customers to pass extra properties to the request body.

    In this case, the request will look like this:

    $additionalProperties = @{
        "template@odata.bind" = "https://graph.microsoft.com/beta/teamsTemplates('standard')"
    }
    $body = @{
        "additionalProperties": $additionalProperties,
        "displayName":"waffleSloth4",
        "description":"waffleSloth4"
    }
    
    New-mgTeam -BodyParameter $body
  3. darrelmiller commented on May 11, 2020

    @darrelmiller
    Contributor

    Peter Ombwa (@peombwa) I think we need to add this "additionalProperties" to every entity, regardless of whether OpenType is true or not. Also, in the other SDKs we call it "additionalData" not "additionalProperties". Let's discuss further.

  4. KirkMunro commented on Jun 9, 2020

    @KirkMunro

    My recommendation would be as follows:

    1. Add a common -PropertyValues parameter of type IDictionary.
    2. Make the use of that parameter possible without having to muck around with JSON or the -BodyParameter. i.e. leave -BodyParameter for the most advanced cases where the cmdlet parameters don't work for you, and use the explicitly defined parameters (e.g. -DisplayName, -Description) combined with the flexible -PropertyValues parameter (which is the property bag) to build the request body that will be sent to Graph.
    3. Rename -BodyParameter as -RequestBody, and give it two aliases: BodyParameter and Body. RequestBody is a more accurate and descriptive name, and -Body is a parameter on Invoke-WebRequest and Invoke-RestMethod, so there is familiarity and ease of discovery. The "Parameter" portion of -BodyParameter seems irrelevant given that it is a PowerShell parameter.
    4. Eliminate the need for unnecessarily complex syntax when associating properties with existing entities. i.e. Instead of "template@odata.bind" = "https://graph.microsoft.com/beta/teamsTemplates('standard')", which is a JSON way of indicating that you want to apply a built-in template to a team, simply use -Template $template or -PropertyValues @{Template = $template}, and handle the conversion to JSON internally.

    With this in place, assuming I already did something like this:

    # Note: This does not work at the moment
    $standardTemplate = Get-MgTeamTemplate -Name Standard

    I could then do this:

    New-MgTeam -DisplayName waffleSloth4 -Description waffleSloth4 -Template $standardTemplate

    or this:

    New-MgTeam -DisplayName waffleSloth4 -Description waffleSloth4 -PropertyValues @{
        Template = $standardTemplate
    }

    or this:

    New-MgTeam -PropertyValues @{
        DisplayName = 'waffleSloth4'
        Description = 'waffleSloth4'
        Template = $standardTemplate
    }

    or if I want access to the raw request, I could do this:

    $body = @"
    {
        "template@odata.bind":"https://graph.microsoft.com/beta/teamsTemplates('standard')",
        "displayName":"waffleSloth4",
        "description":"waffleSloth4"
    }
    "@
    New-MgTeam -RequestBody $body

    These would all work. The first three would simply build the JSON request body that you are sending to Graph to do the work in the last one, rather than have you craft it yourself.

    Also, the idea of "additionalProperties" or "additionalData" seems unnecessary here, especially given that the Graph endpoint doesn't need or use the extra nesting of properties when it is invoked like this:

    POST: https://graph.microsoft.com/beta/Teams {"template@odata.bind":"https://graph.microsoft.com/beta/teamsTemplates('standard')","displayName":"waffleSloth4","description":"waffleSloth4"}
    

    Why add an extra level of nesting when Graph itself doesn't need it?

  5. rhinomerton commented on Jul 28, 2020

    @rhinomerton

    Could you just fix the -Template parameter rather than adding a new feature AdditionalProperties? The property is already explicit. If you do however require Template in AdditionalProperties, please remove the -Template parameter.

  6. linked a pull request that will close this issue0.9.1 bug fixes #342on Aug 28, 2020
  7. peombwa commented on Sep 24, 2020

    @peombwa
    Member

    This has be fixed in v1.0, Install-Module Microsoft.Graph -AllowClobber -Force.

    New-MgTeam -DisplayName $TeamName -Description $TeamDescription `
        -AdditionalProperties @{
            "template@odata.bind" = "https://graph.microsoft.com/beta/teamsTemplates('standard')"
        }

    Updated teams samples can be found here - https://github.com/microsoftgraph/msgraph-sdk-powershell/blob/dev/samples/5-Teams.ps1.

  8. kpinel commented on Jul 22, 2022

    @kpinel

    I know this is an old post but what about adding additional owners? You know, automation and stuff.
    It just seems that we are adding graph structure rather than doing this using cmdlet parameters and having the module to the JSON transform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions