functions/private/Connect-Cloud.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function Connect-Cloud {
    [cmdletbinding()]
    param(
        [parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [pscredential] $credential,
        [parameter()]
        [ValidateNotNull()]
        [string] $TenantId
    )

    begin{}
    process{
        if($TenantId){
            $null = Connect-AzureAD -TenantId $TenantId -Credential $credential
            $null = Add-AzureRmAccount -TenantId $TenantId -Credential $credential
        } else {
            $null = Connect-AzureAD -Credential $credential
            $null = Add-AzureRmAccount -Credential $credential
        }
    }
    end{}
}