Private/Utilities/Get-PSGalleryKey.ps1

function Get-PSGalleryKey() {
        # Start by connecting to our Azure Key Vault.
        $AzContext = Get-AzContext
        if (!$AzContext -or $AzContext.Tenant.Id -ne $script:Config.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 $script:Config.PartnerTenantId -SubscriptionName $script:Config.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
            $PSGalleryKey = Get-AzKeyVaultSecret -VaultName $script:Config.KeyVaultName -Name "psgallerykey" -AsPlainText
        }
        catch {
            Write-Error "Failed to connect to Azure Key Vault and retreive secrets."
        }
    
        return $PSGalleryKey
}