Skip to content

Add-MSTTeamChannelUser

Teams: Adds an owner or member to a private channel

#Requires -Version 5.1

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string]$GroupId,
    [Parameter(Mandatory = $true)]
    [string]$DisplayName,
    [Parameter(Mandatory = $true)]
    [string]$User,
    [ValidateSet('Owner')]
    [string]$Role
)

Process {
    try {
        [string[]]$Properties = @('Name', 'User', 'Role', 'UserID')
        [hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'; 'GroupId' = $GroupId; 'User' = $User; 'DisplayName' = $DisplayName}

        if (-not [System.String]::IsNullOrWhiteSpace($Role)) {
            $cmdArgs.Add('Role', $Role)
        }
        $null = Add-TeamChannelUser @cmdArgs
        $result = Get-TeamChannelUser -GroupId $GroupId -DisplayName $DisplayName -ErrorAction Stop | Sort-Object Name | Select-Object $Properties

        if ($null -eq $result -or $result.Count -eq 0) {
            Write-Output "No channel users found"
            return
        }
        foreach ($item in $result) {
            $item | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format 'yyyy-MM-dd HH:mm:ss') -PassThru -Force
        }
    }
    catch { throw }
}

GroupId of the parent team

Display name of the private channel

User's UPN to add to the channel

User's role in the channel (Owner)

An interactive directory of PowerShell scripts.