Forum Discussion

CFS-BenJ's avatar
CFS-BenJ
Copper Contributor
Jan 07, 2025

Adding External Users in-bulk to: Microsoft Teams & Private Channel(s) within the Team

We have a customer who requires over 350 external users (their customers) to be added / invited into a Team which has been created.

"Half" of the users need to be added into "private channel a", and the other "Half" need to be added into "private channel b".

We have attempted to add the users via various PowerShell scripts, however none of these scripts that we have been provided with have worked for various reasons.

I have been unable to locate any native methods for this within the MS 365 admin centre, therefore believe that the only way to achieve this is by PowerShell scripting.

Example of the most recent script we have is as follows, omitting the creation of the private channel(s) as they have already been created - see below:

We require assistance with the actual script itself to:

Add users into the team from a CSV of their email addresses.

Assign the users to the correct private channel.

Note - users will be added in 2 batches - 1 per private channel, so we just require scripting that can be modified to achieve this.

# Install the Microsoft Teams PowerShell Module

Install-Module -Name PowerShellGet -Force -AllowClobber

Install-Module -Name MicrosoftTeams -Force -AllowClobber

# Connect to Microsoft Teams

Connect-MicrosoftTeams

# Define the team name and path to the CSV file

$teamName = "Your Team Name"

$csvPath = "C:\path\to\your\users.csv"

# Get the GroupId of the team

$team = Get-Team -DisplayName $teamName

$groupId = $team.GroupId

# Import users from the CSV file

$users = Import-Csv $csvPath

# Add external users to the team

foreach ($user in $users) {

    Add-TeamUser -GroupId $groupId -User $user.Email

}

# Define the private channel name

$privateChannelName = "Private Channel Name"

# Create the private channel

New-TeamChannel -GroupId $groupId -DisplayName $privateChannelName -MembershipType Private

# Get the ChannelId of the private channel

$channel = Get-TeamChannel -GroupId $groupId -DisplayName $privateChannelName

$channelId = $channel.Id

# Add users to the private channel

foreach ($user in $users) {

    Add-TeamChannelUser -GroupId $groupId -User $user.Email -ChannelId $channelId

}

 

No RepliesBe the first to reply

Resources