Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 200
Lukas Méndez Duus Avatar asked Jan 26 '26 22:01

Lukas Méndez Duus


2 Answers

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.

like image 131
Amit Baranes Avatar answered Jan 28 '26 22:01

Amit Baranes


If you want to show all key-vault secrets name and their key values then you can use this in powershell

$secrets=Get-AzKeyVaultSecret -VaultName 'key-vault-name'
$secrets | % {Write-Output "$($_.name) $($(Get-AzKeyVaultSecret -VaultName $_.VaultName -Name $_.Name).SecretValue | ConvertFrom-SecureString -AsPlainText)" }
like image 23
khadim hussain Avatar answered Jan 28 '26 20:01

khadim hussain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!