Search code examples
azurepowershellazure-keyvaultpowershell-az-module

Get-AzKeyVaultSecret can't read secret value in Powershell


I'm not able to read the value of one of my secrets in Key Vault. I'm logged in with my Azure account and I have full permission to the selected Key Vault.

I'm able to retrieve a list of available secrets using the following command:

$keyVaultValue = (Get-AzKeyVaultSecret -VaultName 'name-of-key-vault')

And then see the content when I write:

Write-Output $keyVaultValue

But when I ask for a specific key it just returns null:

$keyVaultValue = (Get-AzKeyVaultSecret -VaultName 'name-of-key-vault' -Name 'my-secret-name').SecretValueText

I've checked the name and subscription ID and everything is correct. I can easily read the value from the portal, but no from powershell on my Windows PC.

Any suggestions?


Solution

  • SecretValueText is deprecated, You can use the following syntax the retrieve the value as plain text:

    $keyVaultValue = Get-AzKeyVaultSecret -VaultName 'name-of-key-vault' -Name 'my-secret-name'
    $keyVaultValue.SecretValue | ConvertFrom-SecureString -AsPlainText
    

    More information and examples can be found here.