Public/Support/Session/Test-MicrosoftTeamsConnection.ps1

# Module: TeamsFunctions
# Function: Testing
# Author: David Eberhardt
# Updated: 01-AUG-2020
# Status: Live




function Test-MicrosoftTeamsConnection {
  <#
  .SYNOPSIS
    Tests whether a valid PS Session exists for MicrosoftTeams
  .DESCRIPTION
    A connection established via Connect-MicrosoftTeams is parsed.
  .EXAMPLE
    Test-MicrosoftTeamsConnection
 
    Will Return $TRUE only if a session is found.
  .INPUTS
    System.Void
  .OUTPUTS
    System.Boolean
  .NOTES
    Calls Get-PsSession to determine whether a Connection to MicrosoftTeams (SkypeOnline) exists
  .COMPONENT
    TeamsSession
  .FUNCTIONALITY
    Tests the connection to MicrosoftTeams (SkypeOnline)
  .LINK
    https://github.com/DEberhardt/TeamsFunctions/tree/main/docs/Test-MicrosoftTeamsConnection.md
  .LINK
    https://github.com/DEberhardt/TeamsFunctions/tree/main/docs/about_TeamsSession.md
  .LINK
    https://github.com/DEberhardt/TeamsFunctions/tree/main/docs/
  #>


  [CmdletBinding()]
  [OutputType([Boolean])]
  param() #param

  begin {
    #Write-Verbose -Message "[BEGIN ] $($MyInvocation.MyCommand)"
    Show-FunctionStatus -Level Live
    $Stack = Get-PSCallStack
    $Called = ($stack.length -ge 3)

    #if ( -not $global:TeamsFunctionsMSTeamsModule) { $global:TeamsFunctionsMSTeamsModule = Get-Module MicrosoftTeams }

  } #begin

  process {
    #Write-Verbose -Message "[PROCESS] $($MyInvocation.MyCommand)"
    try {
      $CLI = Get-CsCallingLineIdentity -Identity Global -WarningAction SilentlyContinue -ErrorAction Stop
      if ( $CLI ) { return $true } else { return $false }
    }
    catch {
      return $false
    }
    #>
  } #process

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