Search code examples
azureazure-powershell

Get-AzKeyVaultSecret cannot get plain text secret


I used the syntax below to get the plain text of the secret in AZ powershell:

Get-AzKeyVaultSecret -VaultName 'valt1' -Name 'url' -AsPlainText

However, I got [string]::Format.

I also tried

(Get-AzKeyVaultSecret -VaultName $mongoKeyVault -Name $backendRwUriName).SecretValue, but I got System.Security.SecureString

How can I get the actual secret string as shown in the portal?

Thanks!


Solution

  • After reproducing from my end, I could get the desired results using the below command.

    Get-AzKeyVaultSecret -VaultName "<VAULT_NAME>" -Name "<SECRET_NAME>" -AsPlainText
    

    Unless your secret must be [string]::Format you wont be receiving it as the result.

    Firstly, I have created my secret as below.

    enter image description here

    Below are the results I got using the above command.

    enter image description here