Prerequisites
- Azure subscription (free trial works)
- Azure CLI installed (
az
) or Azure PowerShell - Basic knowledge of networking concepts
- Local RDP client (Windows: built‑in, macOS/Linux: Microsoft Remote Desktop)
Make sure you are signed in to Azure:
az login
Create a Windows VM using the Azure Portal
- Navigate to Portal > Virtual machines and click Create > Azure virtual machine.
- Configure the basics:
- Subscription & Resource group
- Virtual machine name (e.g.,
win-vm-demo
) - Region (e.g.,
East US
) - Image:
Windows Server 2022 Datacenter
- Size:
Standard_B2s
(or any appropriate size)
- Under Administrator account, set a username and a strong password.
- In the Inbound port rules section, allow
RDP (3389)
. - Click Review + create, then Create.
Azure will provision the VM in a few minutes. Once completed, go to the VM’s Overview page to get its public IP address.
Create a Windows VM using Azure CLI
Run the following command, replacing placeholders as needed:
az group create --name MyResourceGroup --location eastus
az vm create \
--resource-group MyResourceGroup \
--name win-vm-demo \
--image MicrosoftWindowsServer:WindowsServer:2022-Datacenter:latest \
--admin-username azureuser \
--admin-password <YourStrongPassword!> \
--size Standard_B2s \
--public-ip-sku Standard \
--assign-identity \
--output json
az vm open-port --resource-group MyResourceGroup --name win-vm-demo --port 3389
The command returns the VM’s public IP. Save it for the next step.
Create a Windows VM using Azure PowerShell
PowerShell script:
Connect-AzAccount
$rgName = "MyResourceGroup"
$location = "EastUS"
$vmName = "win-vm-demo"
$cred = Get-Credential -Message "Enter admin username and password"
New-AzResourceGroup -Name $rgName -Location $location
New-AzVm `
-ResourceGroupName $rgName `
-Location $location `
-Name $vmName `
-Credential $cred `
-Image "Win2022Datacenter" `
-Size "Standard_B2s" `
-PublicIpAddressName "$vmName-pip"
# Open RDP
$nsg = Get-AzNetworkSecurityGroup -ResourceGroupName $rgName -Name "$vmName-nsg"
$rule = New-AzNetworkSecurityRuleConfig -Name "Allow-RDP" -Protocol Tcp -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow
$nsgrule = $nsg | Add-AzNetworkSecurityRuleConfig -Name $rule.Name -NetworkSecurityRule $rule
Set-AzNetworkSecurityGroup -NetworkSecurityGroup $nsgrule
Connect to your Windows VM using RDP
- Open the Remote Desktop Connection app.
- Enter the public IP address of the VM.
- When prompted, provide the admin username and password you set during creation.
- Accept the certificate warning (first‑time connection).
You should now see the Windows desktop.
Delete the VM (cleanup)
To avoid ongoing charges, delete the resources when finished.
# Azure CLI
az vm delete --resource-group MyResourceGroup --name win-vm-demo --yes
az group delete --name MyResourceGroup --yes --no-wait
# PowerShell
Remove-AzVm -ResourceGroupName $rgName -Name $vmName -Force
Remove-AzResourceGroup -Name $rgName -Force