How to use Get-AzKeyVaultSecret in Powershell Azure Function 2.x How to use Get-AzKeyVaultSecret in Powershell Azure Function 2.x powershell powershell

How to use Get-AzKeyVaultSecret in Powershell Azure Function 2.x


Taken from Microsoft: https://docs.microsoft.com/en-us/azure/key-vault/quick-create-powershell

Have you tried dot notation on retrieving those keys?

(Get-AzKeyVaultSecret -vaultName $VaultName -name $KeyName).SecretValueText

If that doesn't work, you may look at this github issue regarding ManagedAppServices: https://github.com/Azure/azure-powershell/issues/8983

Seems to be the same issue you're having.


There is now a new method for this.

$secret = Get-AzKeyVaultSecret -VaultName "<your-unique-keyvault-name>" -Name "ExamplePassword"$ssPtr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($secret.SecretValue)try {  $secretValueText = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($ssPtr)} finally {  [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ssPtr)}Write-Output $secretValueText

Refer to: https://docs.microsoft.com/en-us/azure/key-vault/secrets/quick-create-powershell


Also, please refer to this link if you face any issues due to secretValueText being deprecated.