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

Checking Backup File Date Before Restoring

 Today, I got an interesting request.  I had to check a restore job for a data warehouse analyst.  He said the database wasn't restored ...