Private/Test-IsRmOldConnected.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
26
27
28
<#
.SYNOPSIS
    Test if the AzureRm.Profile olded than v3.0 is already connected to Azure
.DESCRIPTION
    Test if the AzureRm.Profile olded than v3.0 is already connected to Azure
#>

function Test-IsRmOldConnected{
    [CmdLetBinding()]
    [Outputtype("Boolean")]
    $ErrorActionPreference = 'Stop'
    Write-Debug '-- begin - Test-IsRmOldConnected --'
    
    if (-not (Get-Module AzureRm.Profile)) {
        Import-Module AzureRm.Profile
    }
        
    [Boolean] $toReturn = $false
    # AzureRm.Profile < v3.0
    $azureRmProfile = [Microsoft.WindowsAzure.Commands.Common.AzureRmProfileProvider]::Instance.Profile
    if (-not $azureRmProfile.Context.Account.Count) {
        $toReturn = $false
    } else {
        $toReturn = $true
    }

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