Created
November 13, 2017 10:31
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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