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: 360

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 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers