Create Windows 10 Virtual Machine using Azure CLI
How to create a Windows 10 Virtual Machine using Azure CLI
In this example we are creating a Windows 10 Enterprise 21H1 VM in a resource group with an existing VNet
Resource group: prod-ukw-core-rg
VNet: prod-ukw-core-vnet
Subnet: subnet01

Find Azure Windows 10 Virtual Machine Image details: Publisher, Offer and SKU - TechLabs
az vm create options
Private IP address
Because we are not specifying a private IP using the --private-ip-address option, the VM will use dynamic IP addressing.
Public IP address
To create a VM without a public IP address, you can specify an empty variable for Public IP.
--public-ip-address ""
Directly exposing port 3389 for RDP to the Internet is a security risk that will allow brute force password attacks against your VM.
Network Security Group (NSG)
We are not creating a Network Security Group (NSG) for the VM because we already have an NSG attached to the VNet subnet. Again using an empty variable for nsg will create the VM without one.
--nsg ""
VNet and subnet
You can specify the Vnet name and subnet using the --vnet-name and --subnet options
You should create VNets and subnets before deploying any virtual machines
Don't wait for commands to finish
If you add the --no-wait parameter Azure CLI will not wait for a command to finish running before accepting another command.
Using --no-wait allows you to execute multiple commands in a row. Azure CLI will continue running the command operations in the background, making it faster to deploy multiple virtual machines simultaneously.
Storage SKU options
- Standard_LRS creates a standard hdd
- StandardSSD_LRS creates a standard ssd
- Premium_LRS creates a premium ssd
Create a VM using Azure CLI
# define vm variables vmName=prod-ukw-winx01 rgName=prod-ukw-core-rg image=MicrosoftWindowsDesktop:Windows-10:21h1-ent:latest adminuser=cfadmin adminpass="PASSWORD" vnetName=prod-ukw-core-vnet subnet=subnet01 storageSku=StandardSSD_LRS size=Standard_D1_v2 az vm create \ --name $vmName \ --resource-group $rgName \ --image $image \ --admin-username $adminuser \ --admin-password $adminpass \ --vnet-name $vnetName \ --subnet $subnet \ --storage-sku $storageSku \ --size $size \ --public-ip-address "" \ --nsg "" \ --no-wait
Reference:
by Author
Azure CLI - az vm create
https://docs.microsoft.com/en-us/cli/azure/vm?view=azure-cli-latest#az-vm-create
Comments