Microsoft Teams : Governance – Adding External Guest Users to Team and Team Private Channels through PowerShell

.

“Believe you can and you’re halfway there.”

.

Hello Everyone,

Hope you all are doing well.

In this article we are going to discuss how to add the external guest users to teams and teams private channels through PowerShell.

So without getting late, let’s get started.

Background

In our organization, one of our project requirement is to add the guest users to team and the team private channels.

Details

  • Get the Team link / URL, which will help us to add the external guest users to respective Team and Team private channel.
  • It is quite straightforward, Click on “Teams” on the Microsoft Teams menu, click on the ellipses, then “Get link to teams”
Microsoft Teams - Get link to teams
Figure: Microsoft Teams – Get link to teams
  • Copy out the link that looks like below and save on a notepad preferably or any editor of choice.
Teams link / URL
Figure: Teams link / URL
  • Once we have the teams URL, ready with external guest users list.
  • We need to prepare the list in a CSV format and saved in a preferred location.
  • We can use Microsoft Excel , to prepare the external guest users list, then save as .csv
  • Csv file with headings and details for add the external guest users to Team.
Prepare CSV for Team
Figure: Prepare CSV for Team
  • Csv file with headings and details for add the external guest users to Team private channel.
  • Give the Team private channel name under DisplayName here.
Prepare Csv for Team private channel
Figure: Prepare Csv for Team private channel
  • Open PowerShell ISE.
  • Now ran the PowerShell with the following cmdlet to add the external guest users.

Note: The line starting with “#” are just description heading or comment.

Prerequisites

  • Install PowerShell ISE / PowerShell / Visual Studio Code
  • Install Module Microsoft Teams
  • Prepare Csv files to add external guest users to teams and teams private channels.
# Install Microsoft Teams if not installed
Install-Module Microsoft Teams

.

Detailed Steps – PowerShell script

  • Import Microsoft Teams
# Import Microsoft Teams
Import-Module Microsoft Teams
  • Connect to the Microsoft Teams.
# Connect Microsoft Teams of our Tenant
Connect-MicrosoftTeams
  • Enable the settings to allow guest user.
# Enable guest access for Teams
Set-CsTeamsClientConfiguration -AllowGuestUser $True -Identity Global
  • To check your configuration afterwards, run the following cmdlet and make sure that AllowGuestUser is set to $True.
# Check the configuration
Get-CsTeamsClientConfiguration
  • Import the csv file and the details in Teams group.
# Import CSV and add the users to Teams
Import-Csv "E:\PowerShellScripts\guestusers.csv" | foreach{Add-TeamUser -GroupId $_.GroupId -User $_.User}
  • Import the csv file and the details in Teams Private Channel.
# Import CSV and add the users to Teams Channel
Import-Csv "E:\PowerShellScripts\channelusers.csv" | foreach{Add-TeamChannelUser -GroupId $_.GroupId -DisplayName $_.DisplayName -User $_.User}
  • Finally we added the external guest users to teams first and then teams private channels.

Note : If we want to add external guest users to a teams private channel, first we need to add the external guest users to teams and then only we could add the external guest user to required teams private channels.

.

Complete Script

<#
===============================================================================================================================================
Name:           Adding external guest users to Teams and Teams Private Channels through PowerShell
Description:    This script helps to add the external guest users to Teams and Teams Private Channel in an Organization through PowerShell
Version:        1.0
===============================================================================================================================================
#>

# Install Microsoft Teams
#Install-Module Microsoft Teams

# Import Microsoft Teams
Import-Module Microsoft Teams

# Connect Microsoft Teams
Connect-MicrosoftTeams

# Enable guest access for Teams
Set-CsTeamsClientConfiguration -AllowGuestUser $True -Identity Global

# Check the configuration
Get-CsTeamsClientConfiguration

# Import CSV and print the details in output
Import-Csv "E:\PowerShellScripts\guestusers.csv" | foreach{Write-Host GroupId : $_.GroupId User : $_.User}

# Import CSV and add the users to Teams
Import-Csv "E:\PowerShellScripts\guestusers.csv" | foreach{Add-TeamUser -GroupId $_.GroupId -User $_.User}

# Import CSV and print the details in output
Import-Csv "E:\PowerShellScripts\channelusers.csv" | foreach{Write-Host GroupId : $_.GroupId DisplayName : $_.DisplayName User : $_.User}

# Import CSV and add the users to Teams Channel
Import-Csv "E:\PowerShellScripts\channelusers.csv" | foreach{Add-TeamChannelUser -GroupId $_.GroupId -DisplayName $_.DisplayName -User $_.User}

.

Hope this article will help us to add the external guest users to teams and teams private channels through PowerShell.

Also get my article updates on my social media handles.

LinkedIn – https://www.linkedin.com/in/khasim-shaik-8784a1232/

Twitter – https://twitter.com/KhasimShaik2009

Facebook – https://www.facebook.com/profile.php?id=100078255554660

Thank you for your support, will catch up with new article soon.

Keep learning and keep smiling.

Thanks.

Khasim Shaik

SharePoint & Power Platform Developer at OS InfoTech

You may also like...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: