You may have spent some time scrolling through the Secrets section of Azure KeyVault. A few clicks on Load More later and you eventually find the secret you have been looking for:

In order to quicken the process of identifying a secret, I composed the following PowerShell function:

Function List-Secret{
    
    # Receive passed-through parameters from the List-Secret <keyVaultName> <searchTerm>
    # The string parameters received are case-insensitive
    param( [string]$keyVaultName, [string]$searchTerm )
    
    
    # Get secrets from vault based on search criteria stipulated in $searchTerm
    $secrets = Get-AzureKeyVaultSecret -VaultName $keyVaultName | where {$_.Name -like $searchTerm}
    
    # Print to console...
    $secrets | ForEach-Object{
        
        # ... the name of the Key Vault secret
        write-host "`n`n"$_.Name -BackgroundColor Cyan -ForegroundColor Black
    
        # ... the value of the secret
        $secretValueText = (Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name $_.Name).SecretValueText
        Write-Host $secretValueText
    }
} 

This script allows you to specify your KeyVault name and a Search Term.

Instructions

Below are a few instructions on how you can use this script to search for secret values in your KeyVault:

  1. Open and Run the script to produce the Function, List-Secret

2. From the command-line, or defined within the script if you so prefer, run the Function in the following format List-Secret <keyVaultName> <searchTerm>

You will get a response similar to

3. The parameters passed through are not Case-Sensitive

4. You can search using wildcards

  • List-Secret myKeyVaultName *pwd*
  • List-Secret myKeyVaultName Azure*

Download the script:

Or visit my GitHub: