Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.