Private/Test-IsAzConnected.ps1

<#
.SYNOPSIS
    Test if the Az.Accounts is already connected to Azure
.DESCRIPTION
    Test if the Az.Accounts is already connected to Azure
#>

function Test-IsAzConnected {
    [CmdLetBinding()]
    [Outputtype("Boolean")]
    $ErrorActionPreference = 'Stop'
    Write-Debug '-- begin - Test-IsAzConnected --'

    if (-not (Get-Module Az.Accounts)) {
        Import-Module Az.Accounts
    }
    
    $azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
    [Boolean] $toReturn = $false
    if (-not $azProfile.Accounts.Count) {
        $toReturn = $false
    } else {
        $toReturn = $true
    }

    Write-Debug '-- end - Test-IsAzConnected --'
    return $toReturn
}