In this blog post, we’ll cover:
- An introduction to using the Azure CLI for resource management
- How to launch and use Azure Cloud Shell
- Steps to create an Azure Resource Group
- How to deploy a Windows Server 2022 virtual machine (VM)
- Installing the IIS web server remotely
- Opening network ports to allow web traffic
- Accessing the web server in a browser
- Instructions for cleaning up resources to avoid unnecessary costs
Whether you are a developer, system administrator, or IT professional, managing Azure resources via the command line can be faster and more repeatable than clicking through the portal. This quickstart walks you through the process of deploying a Windows Server 2022 virtual machine (VM) using the Azure CLI, installing IIS, and accessing it from the internet.
If you don’t have an Azure subscription, you can create a free account before you begin.
Launch Azure Cloud Shell
To make things simple, we will use the Azure Cloud Shell. It’s a free, browser-based shell with all the Azure tools preinstalled. You don’t need to install anything on your local machine.
You can open the Cloud Shell by selecting Try it in the upper-right corner of any code block in this post, or go directly to shell.azure.com/bash.
Step 1: Create a Resource Group
A resource group is a logical container that holds all your Azure resources. Use the following commands to set your subscription and create a resource group. Replace the variable values as needed.
Azure CLI
az group create --name week03VM1 --location eastus
Step 2: Create the Virtual Machine
Now, let’s create the VM. The command below will create a VM named myVM using the Windows Server 2022 image. You will be prompted to enter a password that meets Azure’s complexity requirements.
Azure CLI
az vm create --name week03VM1 --resource-group week03rg --image Ubuntu2204 --size Standard_B1s --admin-username esuteric --generate-ssh-keys
az vm create --resource-group week03rg --name my-vm --size Standard_DC4s_v3 --public-ip-sku Standard --image Win2022AzureEditionCore --admin-username azureuser --generate-ssh-keys
Note: It takes a few minutes for the VM and its supporting resources to be created.
Once the process completes, you’ll see output similar to this. Make sure to copy the publicIpAddress—you’ll need it later.
json
{
"fqdns": "",
"id": "/subscriptions/<guid>/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
"location": "centralus",
"macAddress": "00-0D-3A-23-9A-49",
"powerState": "VM running",
"privateIpAddress": "10.0.0.4",
"publicIpAddress": "52.174.34.95",
"resourceGroup": "myResourceGroupCLI"
"zones": ""
}
Step 3: Install the IIS Web Server
To see your VM in action, we’ll install the IIS web server using a remote PowerShell command.
Azure CLI
az vm run-command invoke -g week03rg -n my-vm --command-id RunPowerShellScript --scripts "Install-WindowsFeature -name Web-Server -IncludeManagementTools"
Step 4: Open Port 80 for Web Traffic
By default, only RDP (port 3389) is open. To allow web traffic, we need to open port 80.
Azure CLI
az vm open-port --port 80 --resource-group week03rg --name my-vm
Step 5: View the Web Server
Open your browser and navigate to http://<your-public-ip-address>. You should see the default IIS welcome page, confirming your server is up and running.
Clean Up Resources
To avoid incurring unnecessary charges, delete the resource group when you no longer need the VM. This will remove all associated resources.
Azure CLI
az group delete --name week03rg
Final Thoughts
Using the Azure CLI allows you to automate and streamline the deployment of virtual machines. In just a few commands, you went from no infrastructure to a fully functional Windows Server with a web server accessible online.