Read a secret from Azure Key Vault using PowerShell

Read secrets from Azure Key Vault using PowerShell.

John Savill

July 9, 2017

1 Min Read
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

 

About the Author(s)

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like