Skip to content

Get-MSTTeamChannelUser

Teams: Get users of a channel

#Requires -Version 5.1

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

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

        if (-not [System.String]::IsNullOrWhiteSpace($Role)) {
            $cmdArgs.Add('Role', $Role)
        }
        $result = Get-TeamChannelUser @cmdArgs | 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

Filter results to only users with the given role (Member, Owner, Guest)

An interactive directory of PowerShell scripts.