Public/Support/VoiceConfig/Get-TeamsCP.ps1

# Module: TeamsFunctions
# Function: VoiceConfig
# Author: David Eberhardt
# Updated: 01-APR-2021
# Status: Live




function Get-TeamsCP {
  <#
  .SYNOPSIS
    Lists all Teams Calling Policies by Name
  .DESCRIPTION
    To quickly find Teams Calling Policies to assign, an Alias-Function to Get-CsTeamsCallingPolicy
  .PARAMETER Identity
    String. Name or part of the Teams Calling Policy. Can be omitted to list Names of all Policies (including "Global").
    If provided without a '*' in the name, an exact match is sought.
  .EXAMPLE
    Get-TeamsCP
 
    Returns the Object for all Teams Calling Policies (including "Global")
    Behaviour like: Get-CsTeamsCallingPolicy, showing only a few Parameters
  .EXAMPLE
    Get-TeamsCP -Identity AllowCallingPreventTollBypass
 
    Returns the Object for the Teams Calling Policy "AllowCallingPreventTollBypass" (provided it exists).
    Behaviour like: Get-CsTeamsCallingPolicy -Identity "AllowCallingPreventTollBypass"
  .EXAMPLE
    Get-TeamsCP -Identity Allow*
 
    Lists Calling Policies with "Allow" in the Name
    Behaviour like: Get-CsTeamsCallingPolicy -Filter "*Allow*"
  .NOTES
    This script is indulging the lazy admin. It behaves like Get-CsTeamsCallingPolicy with a twist:
    If more than three results are found, a reduced set of Parameters are shown for better visibility:
    Get-CsTeamsCallingPolicy | Select-Object Identity, Description, BusyOnBusyEnabledType
  .INPUTS
    None
    System.String
  .OUTPUTS
    System.Object
  .COMPONENT
    SupportingFunction
    VoiceConfiguration
  .FUNCTIONALITY
    Queries Calling Policies by Name
  .LINK
    https://github.com/DEberhardt/TeamsFunctions/tree/main/docs/Get-TeamsCP.md
  .LINK
    https://github.com/DEberhardt/TeamsFunctions/tree/main/docs/about_VoiceConfiguration.md
  .LINK
    https://github.com/DEberhardt/TeamsFunctions/tree/main/docs/about_Supporting_Functions.md
  .LINK
    https://github.com/DEberhardt/TeamsFunctions/tree/main/docs/
  #>


  [CmdletBinding()]
  param (
    [Parameter(Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName, HelpMessage = 'Name of the Calling Policy')]
    [ArgumentCompleter({ &$global:TfAcSbTeamsCallingPolicy })]
    [string]$Identity
  )

  begin {
    Show-FunctionStatus -Level Live
    Write-Verbose -Message "[BEGIN ] $($MyInvocation.MyCommand)"

    # Asserting MicrosoftTeams Connection
    if ( -not (Assert-MicrosoftTeamsConnection) ) { break }

  } #begin

  process {
    Write-Verbose -Message "[PROCESS] $($MyInvocation.MyCommand)"

    if ($PSBoundParameters.ContainsKey('Identity')) {
      Write-Verbose -Message "Finding Teams Calling Policy with Identity '$Identity'"
      if ($Identity -match [regex]::Escape('*')) {
        $Filtered = Get-CsTeamsCallingPolicy -Filter "*$Identity*" -ErrorAction $ErrorActionPreference
      }
      else {
        $Filtered = Get-CsTeamsCallingPolicy -Identity "$Identity" -ErrorAction $ErrorActionPreference
      }
    }
    else {
      Write-Verbose -Message 'Finding Teams Calling Policy Names'
      $Filtered = Get-CsTeamsCallingPolicy -ErrorAction $ErrorActionPreference # | Where-Object Identity -NE 'Global'
    }

    if ( $Filtered.Count -gt 3) {
      $Filtered = $Filtered | Select-Object Identity, Description, BusyOnBusyEnabledType #, AllowPrivateCalling
    }
    return $Filtered | Sort-Object Identity
  } #process

  end {
    Write-Verbose -Message "[END ] $($MyInvocation.MyCommand)"
  } #end
} # Get-TeamsCP