How to create VM in Azure

Every now and then, I receive many requests from people asking me how to create a Virtual Machine in Azure. This Azure tutorial will explore multiple approaches to achieve this goal, followed by a Video tutorial for your convenience.

How to create VM in Azure

We can create a virtual machine (VM) in Azure for free.

Note: For Azure VM creation for free, you can sign up for a 30-day Azure free trial. Here, we will discuss creating the VM with the new version of Windows Server 2019 Datacenter. Ensure you have a subscription to Azure before beginning. If you don’t have a subscription, create a free Azure account.

Creating Windows VM

Approach 1: Using Azure Portal

To create VM in Azure, follow the steps below.

1. Log in to https://portal.azure.com.

2. Now, click on the “Virtual machines” option from the left side Menu and then click on the Create link.

how to create vm in azure

Or go to the “Virtual machines” option from the “Azure services” section.

create vm in azure

Another option is to navigate to the same setting from the “Create a resource” link in the left-side menu, then select “Compute” and “Virtual machine”.

create virtual machine in azure
how to create a vm in azure

For the same option, you can also go to the “Create a resource” link from the “Azure services” section and then select “Compute” and “Virtual machine”.

steps to create virtual machine in azure

You can see the option “Virtual machine’ like below:

create azure vm

3. Fill in the details required. A few of the options you can keep as it is, but based on your business needs, you can change those.

  • Subscription: Choose your correct subscription.
  • Resource group: You can choose the existing resource group or create a new one by clicking the “Create New” option. It acts like a container that stores the resources related to an Azure solution.
  • Virtual machine name: Provide a name for your virtual machine.
  • Region: This is where you will create all the resources related to the virtual machine.
  • Image: Choose the Windows Server 2019 Datacenter. You can adjust it according to your business needs.
  • Size: The size you want to assign based on your requirements. I have chosen Standard D2s v3 in accordance with my business requirements.

In the Administrator account section, choose a Username and password that you will use to log in to the VM once created.

Select Inbound port: Choose HTTP(80), RDP(3389). This is a very important option.

All other options can be left unchanged. Now click on the “Next: Disks >” button.

how to create vm in azure portal
create virtual machine in azure step by step

Since I do not have a Windows server license, you can select No license.

azure create vm

You can add your desired disk architecture in the next screen (Disks). I kept the default option as it is. You can adjust it according to your business needs. Click on the Next: Networking button.

create vm in azure portal

Now you can fill in the details below in the Networking screen.

  • Virtual Network: Choose a virtual network or create a new one by clicking the “Create New” link.
  • Subnet: You can keep the default option as it is.
  • Public inbound ports: Select ‘Allow selected ports’.
  • Select inbound ports: This is a very important option. Select HTTP (port 80) or RDP (port 3389) here. Once you choose this option in the Basics tab, it will automatically show the same option here. Keep the option as it is.
how to create vm in azure step by step
steps to create vm in azure

You can keep all the options as they are for the other tabs. Once you fill in all the above details, click the “Review + Create” button. Azure will validate the above details internally and show the message “Validation passed.”

how to create windows vm in azure

4. Now, click on the “Create” button. It will display “Your deployment is complete.”Now click on “Go to resource.”

azure vm creation step by step

5. Congratulations. You have now successfully created the VM. Click on the Connect button to connect to the VM.

creating vm in azure

Approach 2: Using PowerShell

Let’s discuss the Prerequisites before we start.

Prerequisites

Below are the steps to follow.

1. Connect To Azure

Open the PowerShell ISE in Run as Administrator mode and execute the following PowerShell cmdlet to connect to Azure using the Connect-AzAccount PowerShell cmdlet.

PS C:\WINDOWS\system32> Connect-AzAccount

Once you execute the above PowerShell cmdlet, it will prompt you to provide your Azure Credentials. Ensure you log in with your Global Administrator credentials.

2. Creating a new resource group using PowerShell

To create an Azure Virtual machine, we need to create a resource group using PowerShell as a first step. Use the below PowerShell script to create a resource group using PowerShell.

PS C:\WINDOWS\system32> New-AzResourceGroup -Name DemoVM -Location "East US"

We have executed the above PowerShell cmdlet, and you can see that the Resource group has been successfully created without any issues.

DemoVM is the name of our resource group, and its region is East US.

how to create virtual machine in azure free account

3. Creating a new virtual network using PowerShell

Now, our resource group is ready, and as a next step, we need to create a new virtual network using PowerShell. Use the below PowerShell cmdlet to create a new virtual network using PowerShell.

$vmsnet = New-AzVirtualNetworkSubnetConfig -Name vmsubnet -AddressPrefix “10.0.2.0/24”

New-AzVirtualNetwork -Name TSINFOVN1 -ResourceGroupName DemoVM -Location “East US” -AddressPrefix “10.0.0.0/16” -Subnet $vmsnet

Once we have executed the above PowerShell script. You can see that the virtual network has been successfully created without any issue

how to create vm in azure using powershell
Name                   : TSINFOVN1
ResourceGroupName      : DemoVM
Location               : eastus
Id                     : /subscriptions/1cdf###-dee5-###-9c9c-feaa72a5cbd1/resourceG
                         roups/DemoVM/providers/Microsoft.Network/virtualNetworks/TSIN
                         FOVN1
Etag                   : W/"8b5818b8-231f-4102-a58c-d4059303c4d6"
ResourceGuid           : 16a24415-7405-4a35-9d00-0920e25bd07e
ProvisioningState      : Succeeded
Tags                   : 
AddressSpace           : {
                           "AddressPrefixes": [
                             "10.0.0.0/16"
                           ]
                         }
DhcpOptions            : {}
Subnets                : [
                           {
                             "Delegations": [],
                             "Name": "vmsubnet",
                             "Etag": "W/\"8b5818b8-231f-4102-a58c-d4059303c4d6\"",
                             "Id": "/subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd
                         1/resourceGroups/DemoVM/providers/Microsoft.Network/virtualNe
                         tworks/TSINFOVN1/subnets/vmsubnet",
                             "AddressPrefix": [
                               "10.0.2.0/24"
                             ],
                             "IpConfigurations": [],
                             "ServiceAssociationLinks": [],
                             "ResourceNavigationLinks": [],
                             "ServiceEndpoints": [],
                             "ServiceEndpointPolicies": [],
                             "PrivateEndpoints": [],
                             "ProvisioningState": "Succeeded",
                             "PrivateEndpointNetworkPolicies": "Enabled",
                             "PrivateLinkServiceNetworkPolicies": "Enabled",
                             "IpAllocations": []
                           }
                         ]
VirtualNetworkPeerings : []
EnableDdosProtection   : false
DdosProtectionPlan     : null

We have successfully created the resource group and the virtual network so far. Now, it is time to create a new Azure VM.

4. Creating an Azure VM using PowerShell

Use the below PowerShell cmdlet to create an Azure Virtual machine.

$loginDetails = Get-Credential

New-AzVm -ResourceGroupName DemoVM -Name “TSINFOVM” -Location “East US” -VirtualNetworkName “TSINFOVN1” -SubnetName “vmsubnet” -addressprefix 10.0.2.0/24 -PublicIpAddressName “TSINFOIP1” -OpenPorts 3389 -Image win2019datacenter -Size Standard_D2s_v3 -Credential $loginDetails

Once we have executed the above PowerShell script, you can see the Azure Virtual Machine has been created successfully without any issue.

how to create virtual machine in azure free account

The output looks like the below

ResourceGroupName        : DemoVM
Id                       : /subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resourc
eGroups/DemoVM/providers/Microsoft.Compute/virtualMachines/TSINFOVM
VmId                     : b90fd30b-cefd-432c-a06f-81598e6dd91d
Name                     : TSINFOVM
Type                     : Microsoft.Compute/virtualMachines
Location                 : eastus
Tags                     : {}
HardwareProfile          : {VmSize}
NetworkProfile           : {NetworkInterfaces}
OSProfile                : {ComputerName, AdminUsername, WindowsConfiguration, 
Secrets, AllowExtensionOperations, RequireGuestProvisionSignal}
ProvisioningState        : Succeeded
StorageProfile           : {ImageReference, OsDisk, DataDisks}
FullyQualifiedDomainName : tsinfovm-a5a358.East US.cloudapp.azure.com

To ensure the virtual machine has been created successfully, let’s log in to the Azure Portal and verify that the VM was created correctly. As shown below, the Azure VM was created successfully without any issues.

create vm in azure powershell

Approach 3: Using Azure CLI

You can also quickly create an Azure Virtual Machine using Azure CLI using the steps below.

1. Create a Resource Group using the below command in Azure CLI.

az group create --name myRsgGroup --location eastus

Once you execute the above command, you will get the output below

{
  "id": "/subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resourceGroups/myRsgGroup",
  "location": "eastus",
  "managedBy": null,
  "name": "myRsgGroup",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null,
  "type": "Microsoft.Resources/resourceGroups"
}

2. Now, run the following command to create the VM using Azure CLI.

az vm create --resource-group myRsgGroup --name TSINFOVM2 --image Win2016Datacenter --admin-username rajkishore --admin-password "Password@123" --location eastus

You can see it below.

create virtual machine in azure cli

Once you execute the above command, you will get the output below

{- Finished ..
  "fqdns": "",
  "id": "/subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resourceGroups/myRsgGroup/providers/Microsoft.Compute/virtualMachines/TSINFOVM2",
  "location": "eastus",
  "macAddress": "00-0D-3A-18-68-6B",
  "powerState": "VM running",
  "privateIpAddress": "10.0.0.4",
  "publicIpAddress": "13.92.35.98",
  "resourceGroup": "myRsgGroup",
  "zones": ""
}

Now, if you verify in the Azure Portal, you can see that the VM was created successfully. Check out the screenshot below, which shows that the Virtual Machine has been created successfully.

how to create a windows virtual machine in azure

How To Create Linux VM In Azure

We have discussed above how to create a Windows virtual machine in Azure. Now, let’s discuss how to create a Linux Virtual Machine in Azure. Follow the steps below.

Creating a Linux VM

Approach 1: Using Azure Portal

1. Follow the step-1 to Step-2 from the above section.

2. On the Create a Virtual Machine page, provide the details below

  • Subscription: Select a valid subscription that you want to use here to create a Linux virtual machine.
  • Resource group: Choose the existing resource group or create a new one by clicking the “Create New” option.
  • Virtual Machine Name: Please provide a name for your virtual machine.
  • Region: Select the region or location.
  • Image: Choose the Ubuntu Server 20.04 LTS – Gen1 as the image option.
  • Size: Select the size based on your business requirements. Click on the “See all sizes” link to view all available options.
  • Authentication Type: Select the authentication type that best suits your needs.
  • Username: Provide a username.
  • SSH public key source: Select the default option. Generate a new key pair.
  • Key Pair Name: Provide a name for the key pair.
  • Public inbound Ports: Select the Allow Selected Ports option.
  • Select Inbound Ports: Select the HTTP (80) and SSH (22) options.

Keep the other tab values unchanged. Finally, click the Review + Create button.

create a virtual machine in azure
how to create virtual machine in azure portal
steps to create virtual machine in azure

3. Now, it will validate all the details you provided and show you ” Validation Passed. ” Click on the Create button to create the Azure Linux Virtual Machine.

4. Click the “Download private key and create resource” button to download the critical details needed for connecting to the virtual machine.

how to create a virtual machine in azure portal

5. It will take a few minutes to show you that your deployment is complete. Click the Go to Resource button to navigate to the Linux Virtual Machine you created.

how to create virtual machine in azure portal

Approach 2: Using Azure CLI

Using the steps below, you can easily create a Linux virtual machine using Azure CLI.

1. Run the below command to create a Resource Group using Azure CLI.

az group create --name demoRsgGroup --location eastus

Once you execute the above command, you will get the output below.

{
  "id": "/subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resourceGroups/demoRsgGroup",
  "location": "eastus",
  "managedBy": null,
  "name": "demoRsgGroup",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null,
  "type": "Microsoft.Resources/resourceGroups"
}

2. Now, execute the following command to create the VM using Azure CLI.

az vm create --resource-group demoRsgGroup --name TSINFOVM --image UbuntuLTS --admin-username azureuser --generate-ssh-keys

You can see it below

azure vm create

Once you execute the above command, you will get the output below

{- Finished ..
  "fqdns": "",
  "id": "/subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resourceGroups/demoRsgGroup/providers/Microsoft.Compute/virtualMachines/TSINFOVM",
  "location": "eastus",
  "macAddress": "00-0D-3A-57-3D-13",
  "powerState": "VM running",
  "privateIpAddress": "10.0.0.4",
  "publicIpAddress": "52.179.10.61",
  "resourceGroup": "demoRsgGroup",
  "zones": ""
}

Now, to verify, you can navigate to the Azure Portal and see the Azure Linux VM created successfully below. Check out the screenshot below.

how to create free virtual machine in azure

You can also use the Azure VM create command to create a virtual machine in Azure.

Video Tutorial

Conclusion

In this Azure tutorial, we have discussed how to create a virtual machine (VM) in Azure using the Azure Portal, PowerShell, Azure CLI, and other methods. I hope you have enjoyed this article !!!

You may like the following Azure tutorials:

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!