Functions/Get-TeamObject.ps1

<#
.SYNOPSIS
    This function retrieves a team object which matches either the provided display name or group ID.
#>

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

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

    # Retrieve the team object
    if ($displayName) {
        $team = Get-Team | Where-Object { $_.DisplayName -eq $displayName }
        if (!$team) {
            Write-Error "No teams match the display name '$($displayName)'."
            return
        }
        elseif ($team.Length -gt 1) {
            Write-Error "More than one team matches the display name '$($displayName)'."
            return
        }
    }
    elseif ($groupId) {
        $team = Get-Team | Where-Object { $_.GroupId -eq $groupId }
        if (!$team) {
            Write-Error "No teams match the group ID '$($groupId)'."
            return
        }
    }
    else {
        Write-Error "Either `$TeamDisplayName or `$TeamGroupId must be provided."
        return
    }
    return $team
}