EXCEPTION: Please provide a valid tenant or a valid subscription.

Dhaval Shah 20 Reputation points
2024-02-23T09:34:25.66+00:00

Hello,

We have one Azure function app function with one Powershell script running. we have stored the value of secrets in the key vault and in the PowerShell script it retrieves from the key vault. when powershell script runs it shows the below error.
[Error] EXCEPTION: Please provide a valid tenant or a valid subscription.

We have checked the vault and the value is correct in the key vault. Please find the attached screenshot of the error.

Can you please help here User's image

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,856 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Deepanshukatara-6769 8,715 Reputation points
    2024-02-23T09:55:16.42+00:00

    Hi , Verify that the Azure Function App has the necessary permissions to access the Key Vault. The managed identity or service principal associated with the Azure Function App should have at least "Get" permissions on secrets in the Key Vault. check document for details to assign permissions on KV https://learn.microsoft.com/en-us/azure/key-vault/general/assign-access-policy?tabs=azure-portal Please accept answer if it helps


  2. Deepanshukatara-6769 8,715 Reputation points
    2024-02-23T11:12:29.1466667+00:00

    Please check this

    try {
        # Retrieve the secret value from Key Vault
        $secret = Get-AzKeyVaultSecret -VaultName "<your-unique-keyvault-name>" -Name "FUN-ONBOARDING-PARAMS" -AsPlainText
    
        # Convert the secret string to a PowerShell hashtable
        $onboardingParams = Invoke-Expression $secret
    
        # Set Azure context using the subscription ID from the retrieved secret
        Set-AzContext -Subscription $onboardingParams.AzSubscription
    }
    catch {
        Write-Host "Error: $_"
    }
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.