helpers/Connect-O365Skype.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function Connect-O365Skype
{
    PARAM
    (
        [System.Management.Automation.PSCredential]
        $Credential
    )

    try
    {
        Import-Module -Name SkypeOnlineConnector -DisableNameChecking -Force -ErrorAction Stop
    }
    catch
    {
        Write-Error -Message "The module 'SkypeOnlineConnector' was not found. A connection to Skype for Business will not be established"
    }
    
    $Option = New-PSSessionOption -IdleTimeout -1
    $SkypeSession = New-CsOnlineSession -Credential $Credential -SessionOption $Option
    $ModuleName = 'SkypeForBusiness'
    $ModulePath = Join-Path $AppdataPath $ModuleName
    $null = Export-PSSession -Session $SkypeSession -OutputModule $ModulePath -AllowClobber -Force
    Import-Module $ModulePath -Global -DisableNameChecking
}