PowerShell: 101-vm-secure-password


Very simple deployment of a Windows VM using password stored in Key Vault

Description

This is an Azure quickstart sample PowerShell script based on ARM template 101-vm-secure-password  from the repository azure\azure-quickstart-templates .

This script allows you to deploy a simple Windows VM by retrieving the password that is stored in a Key Vault. Therefore the password is never put in plain text in the script, and it will deploy the following resources…

Key Vault reference

https://docs.microsoft.com/en-us/azure/key-vault/secrets/quick-create-powershell#create-a-resource-group 

… and in-addition to it, just in-case if the deployment is not successful, then it will rollback the entire deployment.

Note:

If the specified resource group is already exist then the script will not continue with the deployment.

Syntax

Deploy-AzResource.ps1 [-ResourceGroupName] <string> [-Location] <string> [[-DNSLabelPrefix] <string>] [[-WindowsOSVersion] <string>] [[-VMSize] <string>] [-KeyVaultName] <string> [-AdminUserName] <string> [<CommonParameters>]

Example

I 💙 PS> $param = @{
>> ResourceGroupName = 'compute-rg'
>> Location = 'westus'
>> KeyVaultName = 'sgdhjk-kv'
>> AdminUserName = 'sysadmin'
>> }

I 💙 PS> .\Deploy-AzResources.ps1 @param

Output

Deployment is successful!

Code

    View the code in GitHub  
Last modified: 17 September 2020

Share it on     |   |   |   | 
comments powered by Disqus