The zipper file attached helps to provision the teams. It reads the data from a configuration file and creates teams and adds users to the teams.This would be very handy when you have to provision teams and add users at an enterprise level. The following are the files present in the attachment.

  1. Config.xml
  2. Logger.ps1
  3. ProvisionTeams.ps1

The Zipper contains the following files


Config.Xml

This XML file helps you to structure the teams and the people that have to be added into them.

XML
Edit|Remove
<?xml version="1.0" encoding="utf-8"?> 
<Configuration LogFilePath="D:\Usedlog.csv"    <Teams        <Team DisplayName="Test" Description="Test" IsOpen="False" DomainId ="trycatchexp.onmicrosoft.com"             <User Id="tuser1@trycatchexp.onmicrosoft.com" IsOwner="True"/> 
            <User Id="tuser2" /> 
        </Team> 
    </Teams> 
</Configuration>  

 Nodes in Detail

Configuration

XML
Edit|Remove
https://gallery.technet.microsoft.com/Creation-of-Teams-and-356e0dee
 

The Configuration node is an entry node and has an attribute named LogFilePath, which defines the location of the log file path that has to be created/Updated during the execution of the script. All the exceptions and messages are available on this path.

Teams

The Teams node can have multiple Team nodes under it.

Team

The number of team node specifies the number of teams that have to be created or updated.

XML
Edit|Remove
<Team DisplayName="Test" Description="Test" IsOpen="False" DomainId ="trycatchexp.onmicrosoft.com" >

Attribute

Description

DisplayName

The team name that has to be created/ updated

Description

Purpose of the team and would be used for your further inventories

IsOpen

Specifies whether the group is public or private

Public Group -  Team is open anyone in the enterprise would be able to join and the workspaces are easily searchable in the SharePoint site

Private Group – Owners are responsible for users to add and the workspaces are only searchable for the members.

DomainId

The active directory domain id from which users have to be added. This would be appended to the username of the user if it does not have one

 

User

XML
Edit|Remove
<User Id="tuser1@trycatchexp.onmicrosoft.com" IsOwner="True"/>
 

Id

The userid can be the user complete name with the domain name or if there is no name specified the DomainId from the parent would be prepended

IsOwner

An optional attribute, when set to true the user would be considered as the owner of the group, else the user would be added as a member

 

Logger.ps1

This script contains the function that helps you to log exceptions, messages, and warnings to the File as well as to the shell

 

PowerShell
Edit|Remove
Function Log-Message 
param 
    ( 
        [Parameter(Mandatory=$true)] 
        [string]$Message, 
        [Parameter(Mandatory=$true)] 
        [ValidateSet("Verbose","Warning","Error")]  
        [string]$Level, 
        [xml]$Config, 
        [string]$LogFileLocation 
    ) 

 

This function accepts the following parameters and is responsible to write to the shell

 

Parameter Name

Details

Message

A mandatory parameter of what needs to be logged

Level

It can be Verbose, warning or error

Config

An optional parameter an XML content can be passed

LogFileLocation

The path of the log file, it can be optional if Config parameter has been passed

 

Log-MessageAppend

This function accepts the same set of parameters but is responsible for outputting data to a file with the time stamp appended

 

PowerShell
Edit|Remove
if($Config) 
{ 
    If($Config.logfile) 
    { 
        "$(Get-Date -Format s)|$($Level)|$($Message)" >> $Config.logfile 
    } 
} 
if($LogFileLocation) 
{ 
    "$(Get-Date -Format s)|$($Level)|$($Message)" >> $LogFileLocation 
}

 ProvisionTeams.ps1

This core script is responsible for the creation of teams (if it does not exist) and adds the users to the teams. The following are the three major functions defined in the PowerShell script

  1. Provision-Teams
  2. Create-Team
  3. Create-User

Provision-Teams :

This function checks for the module Microsoft teams and also traverses the config file and invokes the respective functions 

PowerShell
Edit|Remove
Param([string]$settingsFile = "Config.xml")

The parameter requires the location of the config file, if not specified it checks the file in the current execution path

Create-Teams :

This function creates Team if it does not exist and logs the respective info

PowerShell
Edit|Remove
Param 
( 
    [string]$teamName, 
    [string]$teamDescription, 
    [boolean]$isOpen, 
    [string]$logFileLocation 
) 

 

This function accepts teamName, teamDescription, isOpen, logFileLocation

Create-User:

This function does not create any user but if the user with the id exists it adds the user to the microsoft teams.

PowerShell
Edit|Remove
Param 
( 
    [string]$userName, 
    [string]$groupId, 
    [string]$role, 
    [string]$logFileLocation 
) 
 

Attribute Name

Description

UserName

User that has to be added to the group

GroupID

The unique id of the team

Role

Values can be as Owner/Member

logFileLocation

The path of the file

Execution

The PowerShell needs to be opened as an administrator to execute these functions.

PowerShell
Edit|Remove
. .\ProvisionTeams.ps1 
Provision-Teams

References

https://www.c-sharpcorner.com/article/microsoft-teams-public-vs-private/

https://www.avepoint.com/blog/office-365/microsoft-office-365-groups-public-vs-private-groups/