Script repository
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
This is great thanks.
IS there anyway to add parameters for a owner and members?
Support
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.
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
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: