Private/Curanet/Get-CuranetSessionCredentials.ps1

function Get-CuranetSessionCredentials() {
    param (
        [Parameter(Mandatory)]
        [ValidateSet("3370", "3850")]
        [string]$Account
    )
    # Start by connecting to our Azure Key Vault.
    $AzContext = Get-AzContext
    if (!$AzContext -or $AzContext.Tenant.Id -ne $PartnerTenantId) {
        try {
            Write-Host "Please log in to Azure with your @jlhosting.dk account. A browser window has been opened." -ForegroundColor Yellow
            Connect-AzAccount -Tenant $PartnerTenantId -SubscriptionName $SubscriptionName | Out-Null
        }
        catch {
            Write-Error "Failed to connect to Azure. Please make sure you have the Az module installed."
        }
    }
    try {
        # Retreive all required values from Azure Key Vault
        $CuranetUsername = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name "curanet$($Account)username" -AsPlainText
        $CuranetPassword = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name "curanet$($Account)password" -AsPlainText

        $CuranetSessionCredentials = @{
            Username = $CuranetUsername
            Password = $CuranetPassword
        }
    }
    catch {
        Write-Error "Failed to connect to Azure Key Vault and retreive secrets: $_"
    }

    return $CuranetSessionCredentials
}