Private/Get-InstalledModuleForAzureToken.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
29
30
31
32
33
<#
.SYNOPSIS
    Investigate if module for connect Azure is installed and return version.
.DESCRIPTION
    Investigate if module for connect Azure is installed and return version.
.EXAMPLE
    $TypeOfModuleToConnectIntoAzure = Get-InstalledModuleForAzureToken
#>

function Get-InstalledModuleForAzureToken {
[CmdLetBinding()]
[Outputtype("String")]
param ()
    $ErrorActionPreference = 'Stop'
    Write-Debug '-- begin - Test-IsPossibleGetCredentialFromProfile --'
    $toReturn = 'none'
    $IsAzInstalled = Get-Module -Name Az.Accounts
    if(![String]::IsNullOrEmpty($IsAzInstalled)) {
        $toReturn = 'Az'
    }
    $IsAzInstalled = Get-Module -Name AzureRm.Profile
    if(![String]::IsNullOrEmpty($IsAzInstalled)) {
        if(![String]::IsNullOrEmpty($IsAzInstalled.Version) `
        -and ![String]::IsNullOrEmpty($IsAzInstalled.Version.Major) `
        -and $IsAzInstalled.Version.Major -ge 3) {
            $toReturn = 'Rm3'
        } else {
            $toReturn = 'RmOld' 
        }
    }

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