Select Language:
If you want to create a Windows virtual machine in Azure using the command line, here’s a simple step-by-step guide to help you do it efficiently. We’ll set up the VM in the East US 2 region, choose a DSv2 size, and use the latest Windows Server image.
Start by setting your account and resource group. Make sure to change the names and subscription ID to match your setup:
First, define your subscription ID, resource group name, and location:
bash
subscription=”
resourcegroup=”myResourceGroupCLI”
location=”eastus2″
az account set –subscription $subscription
az group create –name $resourcegroup –location $location
This will prepare your environment and create the resource group where your VM will live.
Next, create the virtual machine with all the necessary details. We’ll use the latest Windows Server 2022 Azure Edition Core image, a Standard_DS1_v2 size, and set up an admin user:
bash
vmname=”myVM”
username=”azureuser”
az vm create \
–resource-group $resourcegroup \
–name $vmname \
–location $location \
–image Win2022AzureEditionCore \
–size Standard_DS1_v2 \
–public-ip-sku Standard \
–admin-username $username
When the command prompts for a password, make sure it meets Azure’s password requirements. You can also include the password directly in the command by adding --admin-password <yourpassword>, but be cautious with security.
If your VM will serve web traffic, you might want to install IIS (Internet Information Services) and open port 80. You can do this easily with a couple of commands:
bash
az vm run-command invoke -g $resourcegroup \
-n $vmname \
–command-id RunPowerShellScript \
–scripts “Install-WindowsFeature -name Web-Server -IncludeManagementTools”
az vm open-port –port 80 –resource-group $resourcegroup –name $vmname
Once the VM is set up, check the output from the creation command to find the public IP address. You’ll use this IP to connect via Remote Desktop Protocol (RDP) or through your web browser if you’ve set up IIS.
Following these steps ensures a straightforward way to set up a Windows VM on Azure with the right specifications and prepare it for web hosting if needed.




