Create a Microsoft Team with single/multiple owners/users using PowerShell

By Saad Khamis

November 14, 2021

23360 views

In this blog I will share one way to create a Microsoft Team with single/multiple owners/users PowerShell. Owners and users are added using either user’s full name or user’s UPN.

Introduction

My blogs have relatively simple, and sometimes complex, examples. I’m hoping that you will be able to tailor them to your need or use them in your own scripts.

The goal of this blog is to show one way to accomplish a task. It is not to show how to write a perfect script, solution or process to accomplish a task.

Prerequisites

  1. The cmdlets for creating and managing teams are in the Microsoft Teams PowerShell module. First thing to remember is to install Install Microsoft Teams PowerShell Module. Otherwise, you can use Cloud Shell if you prefer to stay within Azure Portal.
    Install-Module -Name MicrosoftTeams -Force

PowerShell Cmdlets

  1. Add-TeamUser This cmdlet adds an owner or member to the team, and to the unified group which backs the team.
  2. Connect-AzAccount Connect to Azure with an authenticated account for use with cmdlets from the Az PowerShell modules.
  3. Connect-MicrosoftTeams This cmdlet connects an authenticated account for use with cmdlets from the MicrosoftTeams module.
  4. Get-AzADUser Filters active directory users.
  5. Get-Team This cmdlet supports retrieving teams with particular properties/information, including all teams that a specific user belongs to, all teams that have been archived, all teams with a specific display name, or all teams in the organization.
  6. New-Team This cmdlet lets you provision a new Team for use in Microsoft Teams and will create an O365 Unified Group to back the team. Groups created through teams cmdlets, APIs, or clients will not show up in Outlook by default.
  7. Remove-Team This cmdlet deletes a specified Team from Microsoft Teams. NOTE: The associated Office 365 Unified Group will also be removed.

Connect to Microsoft Teams

Set script variables

First, we will define variables to hold the new team values. Most of the times, the requester will provide users’ names and not users’ UPN. That is why I decided to include both in the Owners and Users variables.

Function to get User’s UPN

Since variables have user’s full name, DisplayName, we have to convert that to user’s UPN using Get-AzADUser.

Function to get user's UPN from user's display name

Does the Team already exist?

First, we will check if the team already exists. If it does, display an error message and stop.

Create new Team with single or multiple owners

Add single or multiple users/members

Without delay, our complete amazing Script

Putting all the pieces together produce a nice script. What’s more, you can add convert the script to a function and add it to your library.

Putting our amazing script to work

Example to illustrate the usage of our amazing script.

Create Team with Owners and Members.

Clean up resources

In conclusion

In summary, we explored writing a script to create a Microsoft Team using PowerShell including adding a single or multiple owners and users. Owners and users are added using either user’s full name or user’s UPN.

Did you find this blog easy to follow and helpful to you? I certainly would love to hear your feedback and suggestions. So, let me know in the comments below. Happy PowerShelling.

Disclaimer

Purpose of the code contained in blog is solely for learning and demo purposes. Author will not be held responsible for any failure or damages caused due to any other usage.

Comments

There's no comments

Leave a Reply

Your email address will not be published. Required fields are marked *