Skip navigation
Read a secret from Azure Key Vault using PowerShell

Read a secret from Azure Key Vault using PowerShell

Q. How can I create and read a secret from Azure Key Vault using PowerShell?

A. I recently wanted to try using Azure Key Vault using PowerShell and wanted to store a sensitive password in Key Vault which could then be used by a script (note in real-world I would further lock down the ACL on the secret in key vault to restrict maybe only a certain registered application could actually read it).

#Create a new vault that supports HSM-protected keys (premium)
New-AzureRmKeyVault -VaultName 'SavillVault' -ResourceGroupName 'RG-SCUSA' -Location 'South Central US' -SKU Premium

#Create a new secret
$secretvalue = ConvertTo-SecureString 'Pa55wordT0p' -AsPlainText -Force

#Store the secret in Azure Key Vault
$secret = Set-AzureKeyVaultSecret -VaultName 'SavillVault' -Name 'JohnPassword' -SecretValue $secretvalue

#Look at the URL and value
$secret.Id
$secret.SecretValue

#Get the secret text
(Get-AzureKeyVaultSecret –VaultName 'SavillVault' -Name JohnPassword).SecretValueText

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish