Functions/Get-TeamChannelObject.ps1

<#
.SYNOPSIS
    This function retrieves a team channel object when provided the channel display name and
    either the team display name or group ID.
#>

function Get-TeamChannelObject {
    [CmdletBinding(PositionalBinding=$false)]
    [OutputType([PSObject])]
    param (
        # The display name of the team.
        [Parameter(Mandatory=$false)]
        [AllowNull()]
        [String]$teamDisplayName,

        # The group ID of the team
        [Parameter(Mandatory=$false)]
        [AllowNull()]
        [String]$teamGroupId,

        # The display name of the channel.
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String]$channelDisplayName
    )

    # Retrieve the team
    $team = Get-TeamObject -DisplayName $teamDisplayName -GroupId $teamGroupId
    if (!$team) {
        return
    }

    # Retrieve the team channel
    $channel = Get-TeamChannel -GroupId $team.GroupId | Where-Object { $_.DisplayName -eq $channelDisplayName }
    if (!$channel) {
        Write-Error "No channels match the display name '$($channelDisplayName)'."
        return
    }
    elseif ($channel.Length -gt 1) {
        Write-Error "More than one channel matches the display name '$($channelDisplayName)'."
        return
    }
    return $channel
}