Functions/Disconnect-SkypeForBusinessOnline.ps1

<#
.SYNOPSIS
    This function disconnects from the current Skype for Business Online session.
.DESCRIPTION
    This function disconnects from the current Skype for Business Online session
    It returns whether the disconnect was successful.
#>

function Disconnect-SkypeForBusinessOnline {
    [CmdletBinding(PositionalBinding=$false)]
    [OutputType([Bool])]
    param ()

    # Retrieve sessions
    $skypeSession = ConvertTo-Array (Get-PSSession | Where-Object { $_.Name -eq "SkypeForBusinessOnline" })

    # Disconnect the sessions
    if ($skypeSession.length -gt 0) {
        foreach ($session in $skypeSession) {
            $session | Remove-PSSession
        }
        Write-Information "Disconnected Skype for Business Online session(s)."
        return $true
    }

    # There are no existing sessions
    else {
        Write-Warning "Attempting to disconnect Skype for Business Online session when there isn't one running."
        return $false
    }
}