Public/ElementsConnectApi.ps1


function Connect-Elements {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $true)]
        [String]${Url},
        [Parameter(Mandatory = $true)]
        [String]${ClientId},
        [Parameter(Mandatory = $true)]
        [System.Security.Cryptography.X509Certificates.X509Certificate2]${Cert},
        [Parameter(Mandatory = $false)]
        [Bool]${ViewToken}
    )
    PROCESS {
        $IdentityServiceUri = 'https://identity-public.sharepointguild.com'
        if ($Url -eq 'https://graph.avepointonlineservices.com/partner') {
            $IdentityServiceUri = 'https://identity.avepointonlineservices.com'
        } elseif($Url -eq 'https://graph-public.sharepointguild.com/partner') {
            $IdentityServiceUri = 'https://identity-public.sharepointguild.com'
        }else {
            return "URL Address Error";
        }
        $Token = Get-IdentityServiceToken -IdentityServiceUri $IdentityServiceUri -ClientId $ClientId -Cert $Cert
        $Configuration = Get-ElementsConfiguration
        $Configuration["BaseUrl"] = $Url
        $Configuration["AccessToken"] = $Token
        if ($ViewToken -eq $true) {
            return $Token
        }
    }
}

function Disconnect-Elements {
    [CmdletBinding()]
    Param()
    PROCESS {
        $Configuration = Get-ElementsConfiguration
        $Configuration["BaseUrl"] = $null
        $Configuration["AccessToken"] = $null
    }
}