add users to channel

Roger Roger 7,081 Reputation points
2025-05-11T22:58:16.6+00:00

Hi All

I want to add users to a Teams channel. Could someone please validate the syntax and let me know if it is correct? i have not tested it.

$teamGroupId = "Microsoft 365 Group ID"

$channelDisplayName = "your_private_channel_name"

# Path to the CSV file (ensure it has a column named 'UserEmail')
$csvPath = "C:\temp\list.csv"
$users = Import-Csv -Path $csvPath
Connect-MicrosoftTeams

foreach ($user in $users) {
    $email = $user.UserEmail
    if ($email) {
        try {
            Add-TeamChannelUser -GroupId $teamGroupId -DisplayName $channelDisplayName -User $email -ErrorAction Stop
            Write-Host "Successfully added $email to channel $channelDisplayName"
        } catch {
            Write-Warning "Failed to add $email: $_"
        }
    } else {
        Write-Warning "Missing UserEmail in CSV row: $($user | Out-String)"
    }
}

Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
3,891 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.