Script repository

Create new team for a user in Microsoft Teams

Updated on: Jan 18, 2026, Views: 4192

Microsoft 365

The script creates a new team for a user in Microsoft Teams. To execute the script, create a custom command configured for the User object type.

To use the script, install the Microsoft Teams PowerShell module on the computer where Adaxes service runs.

Parameters

  • $teamNameParamName - 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 - 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
$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 4

You must be signed in to comment.

  • Stuart Wilkinson

    Stuart Wilkinson

    This is great thanks.
    IS there anyway to add parameters for a owner and members?

  • Mike Sheppard

    Mike Sheppard

    I am trying to implement this script, I've installed the module on the Adaxes server but it's failing

    Create a Microsoft Teams Group - 1 operation executed
    Run PowerShell script 'Create MS Team' for the user
    [Error] The term 'Disconnect-MicrosoftTeams' is not recognized as a name of a cmdlet, function, script file, or executable program.
    Check the spelling of the name, or if a path was included, verify that the path is correct and try again. Stack trace: at , : line 29
    [Error] The term 'Connect-MicrosoftTeams' is not recognized as a name of a cmdlet, function, script file, or executable program.
    Check the spelling of the name, or if a path was included, verify that the path is correct and try again. Stack trace: at , : line 21

    Let me know what I am missing.

    • Support

      Support

      Hello Mike,

      Unfortunately, this is a known issue related to the changes Microsoft made for the MicrosoftTeams PowerShell module in the latest versions. As per our investigation, the 6.9.0 version of the module definitely works with Adaxes. Please uninstall all versions of the module and install version 6.9.0 on the computer where the Adaxes service runs. After the installation, restart the Softerra Adaxes Service Windows service. To install the required version, use the following command:

      Install-Module -Name MicrosoftTeams -RequiredVersion 6.9.0
      

Got questions?

Support Questions & Answers

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.