Thursday, May 30, 2024

Retrieving an Azure Key Vault secret using Powershell

 Here's the script I used to retrieve secrets from an Azure Key Vault.

Clear-Host

$VaultName = "your-vault-name"
Write-Output ""
$SearchName = Read-Host -prompt "Secret Name "
$secretName = $SearchName
$secretValue = $(Get-AzKeyVaultSecret -VaultName $VaultName -Name $secretName -AsPlainText)
Write-Output "$($secretName) | $($secretValue)"


I used to have this script searching the whole key vault using the -match  operator based on a search string.  But I have changed that since because it tries to access the key vault a lot which in the future might cause issues if we get some sort of auditing to the key vault resource.  Also, I find it really slow to return anything when the key vault is fully populated with thousands of secrets.

No comments:

Post a Comment

Little script to see the backup history

 Today, I was teaching a co-worker how to create a copy only backup of a SQL Managed Instance database.  And I came up to use this script t...