Skip to content

Instantly share code, notes, and snippets.

@faizan002
Created November 13, 2017 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faizan002/f987defd92389689229c57162ab69ae7 to your computer and use it in GitHub Desktop.
Save faizan002/f987defd92389689229c57162ab69ae7 to your computer and use it in GitHub Desktop.
Create a Vault In Azure to store password and retrieve it to use in Credentials object. (Powershell Azure automation)
$password="super secret value"
$VaultName="SomeName"
$KeyName="KeyToStorePassword"
$ResourceGrpName="MyExistingResourceGroupName"
$loc="chose a valid value"
New-AzureRmKeyVault -VaultName $VaultName -ResourceGroupName $ResourceGrpName -Location $loc # (This creates a vault)
$PasswordAsSecureString = ConvertTo-SecureString -String $password -AsPlainText -Force
Set-AzureKeyVaultSecret -VaultName $VaultName -Name $KeyName -SecretValue $PasswordAsSecureString
# Retrieve vault key and create a Credential object.
$UserName="mysuer"
$PasswordForCredentials = Get-AzureKeyVaultSecret -VaultName $VaultName -Name $KeyName
$PasswordAsSecureString = ConvertTo-SecureString -String $PasswordForCredentials.SecretValueText -AsPlainText -Force
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $UserName, $PasswordAsSecureString
# This credential object can be used to create a VM (for example)
# An advantage is: you can fully automate VM Creation without storing password in version control.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment