We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script repository

Create new team for a user in Microsoft Teams

May 29, 2023 Views: 1235

The script creates a new team for a user in Microsoft Teams. The script requires the MicrosoftTeamsPowerShell module to be installed on the computer where Adaxes service runs. To execute the script, create a custom command configured for the User object type. The user on which the command is executed will be set as the new team owner.

Parameters:

  • $teamNameParamName - Specifies the name of the parameter used to enter the team name with the param- prefix. The parameter must be of the Edit box type.
  • $teamVisibilityParamName - Specifies the name of the parameter used to select the team visibility with the param- prefix. The parameter must be of the Drop-down list type with the following values only:
    • Public
    • Private
Edit Remove
PowerShell
$teamNameParamName = "param-teamName" # TODO: modify me
$teamVisibilityParamName = "param-visibility" # TODO: modify me

if ($NULL -eq $Context.TargetObject.AzureId)
{
    $Context.LogMessage("The user doesn't have an account in Microsoft 365", "Warning")
    return
}

# Get parameter values
$teamName = $Context.GetParameterValue($teamNameParamName)
$teamVisibility = $Context.GetParameterValue($teamVisibilityParamName)

# Get access tokens for Graph API and Microsoft Teams
$graphToken = $Context.CloudServices.GetAzureAuthAccessToken()
$teamsToken = $Context.CloudServices.GetAzureAuthAccessToken("48ac35b8-9aa8-4d74-927d-1f4a14a0b239")

try
{
    # Connect to Microsoft Teams
    Connect-MicrosoftTeams -AccessTokens @($graphToken, $teamsToken)
    
    # Create new team
    New-Team -DisplayName $teamName -Visibility $teamVisibility -Owner $Context.TargetObject.AzureId
}
finally
{
    # Close the connection and release resources
    Disconnect-MicrosoftTeams -Confirm:$False
}
Comments 2
avatar
Stuart Wilkinson Sep 01, 2025
This is great thanks.
IS there anyway to add parameters for a owner and members?
avatar
Support Sep 01, 2025
Hello Stuart,

To specify an owner for a new team, use the corresponding parameter of the New-Team cmdlet. As for members, they can only be added after the team is already created. For examples, have a look at the Microsoft article: https://learn.microsoft.com/en-us/powershell/module/microsoftteams/new-team?view=teams-ps.
Leave a comment
Loading...

Got questions?

Support Questions & Answers