How to Create Azure VM (Virtual Machine)

How to Create Azure VM (Virtual Machine)

In this azure tutorial, we will discuss How to How to Create Azure VM (Virtual Machine). Apart from this, we will also discuss on the below topics

  • How to create a free virtual machine in the Azure
  • Virtual machine in azure
  • How to create an Azure virtual machine by using PowerShell
  • How to create a windows virtual machine (VM) in Azure
  • Create an Azure virtual machine by using PowerShell
  • How To Create Free Virtual Machine In Azure
  • Azure Create VM PowerShell
  • How To Create A Virtual Machine Using Azure CLI
  • How To Create Linux VM In Azure
  • How To Create Virtual Machine In Azure Step By Step
  • Create Linux VM Using Azure CLI
  • Command To Create Virtual Machine In Azure
  • az vm create

How to Create Azure VM (Virtual Machine)

We can create a windows virtual machine (VM) in Microsoft Azure for free or How to create a free Azure VM

Note: To create an Azure VM for free, you can sign up for a 30-days Azure free trial.

How To Create Free Virtual Machine In Azure

Follow the below steps to create a virtual machine in Azure.

Here, we will discuss How to Create Azure VM (Virtual Machine) with the new version of Windows Server 2019 Datacenter or how to create a VM in Azure portal step by step.

Make sure you have a subscription to azure before starting. If you don’t have a subscription then create a free Azure account.

Assuming you have an Azure subscription now. Follow the below steps to create a windows virtual machine.

Step-1: Login to https://portal.azure.com.

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

How to create a virtual machine in azure

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

How to create a windows virtual machine in azure

One more way is to go to the same option from the “Create a resource” link from the left side menu and then select the “Compute” and “Virtual machine”.

azure virtual machine
azure vm
virtual machine in azure

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

How to create a virtual machine

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

microsoft virtual machine

Step- 3: Fill the details required. A few of the options you can keep as it is but based on your business need you can change those.

  • Subscription: Choose your correct subscription.
  • Resource group: You can choose the existing resource group or you can 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 the location where you are going to create all the resources related to the virtual machine.
  • Image: Choose the Windows Server 2019 Datacenter. You can change it based on your business need.
  • Size: The size you want to assign based on your requirement. I have chosen Standard D2s v3 as per my business requirement.

In the Administrator account section, Choose a Username, Password that you will use to login to the VM once created.

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

All other options you can keep as it is. Now click on “Next:Disks >” button.

microsoft azure virtual machine
Create an azure virtual machine

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

azure free vm

In the next screen (Disks), you can add the disk architecture that you want. I kept the default option as it is. You can change it based on your business need. Click on Next: Networking button.

azure windows vm

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

  • Virtual Network: Choose a virtual network or else you can create a new one by clicking the “Create New” link.
  • Subnet: You can keep the default option as it is.
  • Public inbound ports: choose Allow selected ports.
  • Select inbound ports: This is a very important option. Choose the option as HTTP(80), RDP(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.
microsoft azure vm
Why to use azure virtual machine

Now for other tabs all the options you can keep as it is. Once you fill all the above details click on the “Review + Create” button. Azure will validates the above details internally and will show a message “Validation passed”.

azure free virtual machine

Step- 4: Now click on the “Create” button. It will show you “Your deployment is complete“.Now click on “Go to resource”

creating vm in azure

Step- 5: Congratulations, Now you have created the VM successfully. Click on the Connect button to connect to the VM.

How to create a VM in Microsoft azure

Well, we discussed How to Create Azure VM (Virtual Machine)

How to create an Azure VM (virtual machine) using PowerShell

Above, we discussed How to Create Azure VM (Virtual Machine) using Azure Portal. Let’s see here how to to create an Azure VM (virtual machine) by using PowerShell.

Azure Create VM PowerShell

To start with make sure you have installed Azure PowerShell Az 1.0 or later version. You can use the below command

Install-Module Az

Now Login to your Azure account

Login-AzAccount

user object creation

$credentials = Get-Credential -Message "Enter your username and password for the virtual machine."

Resource group creation

$vmresourceGroup = "MyDev"

$location = "(Asia pacific) Central India"

New-AzureRmResourceGroup -Name $vmresourceGroup  -Location $location

Subnet configuration 

$SubnetName = "Mydevsubnet"
$subnetConfiguration = New-AzureRmVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix 10.50.1.0/24

Virtual Network creation

$Networkname = "DevNet"
$vmresourceGroup = "MyDev"
$Devnet = New-AzureRmVirtualNetwork -ResourceGroupName $vmresourceGroup-Location $location -Name $Networkname -AddressPrefix 10.50.1.0/24 -Subnet $subnetConfiguration

Public IP Address creation

$vmresourceGroup = "MyDev"
$location = "(Asia pacific) Central India"
$publicdn = "dev-cdn"
$publicIP = New-AzureRmPublicIpAddress -ResourceGroupName $vmresourceGroup -Location $location -Name "$publicdn$(Get-Random)" -AllocationMethod Static -IdleTimeoutInMinutes 5

Rule for Port 3389

$NameRDP = "Default-RDP"
$location = "(Asia pacific) Central India"
$portRule = New-AzureRmNetworkSecurityRuleConfig -Name $NameRDP  -Protocol Tcp  -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow

Network security group creation

$SecurityGroupName = "DevNetworkSecurity"
$location = "(Asia pacific) Central India"

$securitygroup = New-AzureRmNetworkSecurityGroup -ResourceGroupName $vmresourceGroup -Location $location 
-Name $SecurityGroupName -SecurityRules $portRule

Virtual network card creation

$NameNetworkCard = "DevNetworkCard"
$location = "(Asia pacific) Central India"
$networkcard = New-AzureRmNetworkInterface -Name $NameNetworkCard -ResourceGroupName $vmresourceGroup -Location $location -SubnetId $Devnet.Subnets[0].Id -PublicIpAddressId $publicIP.Id -NetworkSecurityGroupId $securitygroup.Id

Virtual machine configuration

$vmName = "MyAzureVM"
$MYVMSize = "Standard_D1_v2"
$vmConfiguration = New-AzureRmVMConfig -VMName $vmName -VMSize $MYVMSize | Set-AzureRmVMOperatingSystem -Windows -ComputerName $vmName -Credential $credentials | Set-AzureRmVMSourceImage -PublisherName MicrosoftWindowsServer - WindowsServer -Skus 2019 -Datacenter -Version latest | Add-AzureRmVMNetworkInterface -Id $networkcard.Id

VM Creation

New-AzureRmVM -ResourceGroupName $vmresourceGroup -Location $location -VM $vmConfiguration

Now here is the complete Script

$vmresourceGroup = "MyDev"
$location = "(Asia pacific) Central India"
$SubnetName = "Mydevsubnet"
$NameRDP = "Default-RDP"
$SecurityGroupName = "DevNetworkSecurity"
$vmName = "MyAzureVM"
$MYVMSize = "Standard Ds1_v2"
$Networkname = "DevNet"
$NameNetworkCard = "DevNetworkCard"
$publicdn = "dev-cdn"

$credentials = Get-Credential -Message "Enter your username and password for the virtual machine."

New-AzureRmResourceGroup -Name $vmresourceGroup  -Location $location

$subnetConfiguration = New-AzureRmVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix 10.50.1.0/24
$Devnet = New-AzureRmVirtualNetwork -ResourceGroupName $vmresourceGroup-Location $location -Name $Networkname -AddressPrefix 10.50.1.0/24 -Subnet $subnetConfiguration

$publicIP = New-AzureRmPublicIpAddress -ResourceGroupName $vmresourceGroup -Location $location -Name "$publicdn$(Get-Random)" -AllocationMethod Static -IdleTimeoutInMinutes 5

$portRule = New-AzureRmNetworkSecurityRuleConfig -Name $NameRDP  -Protocol Tcp  -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow

$securitygroup = New-AzureRmNetworkSecurityGroup -ResourceGroupName $vmresourceGroup -Location $location 
-Name $SecurityGroupName -SecurityRules $portRule

$networkcard = New-AzureRmNetworkInterface -Name $NameNetworkCard -ResourceGroupName $vmresourceGroup -Location $location -SubnetId $Devnet.Subnets[0].Id -PublicIpAddressId $publicIP.Id -NetworkSecurityGroupId $securitygroup.Id

$vmConfiguration = New-AzureRmVMConfig -VMName $vmName -VMSize $MYVMSize | Set-AzureRmVMOperatingSystem -Windows -ComputerName $vmName -Credential $credentials | Set-AzureRmVMSourceImage -PublisherName MicrosoftWindowsServer - WindowsServer -Skus 2019 -Datacenter -Version latest | Add-AzureRmVMNetworkInterface -Id $networkcard.Id

New-AzureRmVM -ResourceGroupName $vmresourceGroup -Location $location -VM $vmConfiguration

How To Create A Virtual Machine Using Azure CLI

Well, You can also quickly able to create a VM using Azure CLI. Use the below steps to create a virtual machine using Azure CLI.

Step-1: Create a resource group using the below command in Azure CLI.

az group create --name myRsgGroup --location eastus

Once you will execute the above command, you will get the output like 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"
}

Step-2: Now, run the below command to create the VM in using Azure CLI.

az vm create --resource-group myRsgGroup --name TSINFOVM2 --image Win2016Datacenter --admin-username rajkishore --admin-password "[email protected]" --location eastus

You can see it as below

How To Create A Virtual Machine Using Azure CLI

Once You will execute the above command, you will get the output like 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 will verify on the Azure Portal, you can able to see the VM created successfully.

Create A Virtual Machine Using Azure CLI

How To Create Linux VM In Azure

Well, we have discussed above, How to create a Windows virtual machine in the Azure portal. Now let’s discuss here, how to create Linux Virtual Machine in Azure.

How To Create Virtual Machine In Azure Step By Step

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

Step-2: On the Create a Virtual Machine page, Provide the below details

  • 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 you can create a new one by clicking the “Create New” option.
  • Virtual machine name: You need to 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 requirement. Click on the see all sizes link to check all the options available.
  • Authentication Type: Select the authentication type based on your need.
  • Username: Provide a username.
  • SSH public key source: Select the default option Generate 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), SSH (22) option.

Keep the other tab values as it is, Finally click on the Review + Create button.

Create a Linux virtual machine in the Azure portal
How To Create Linux VM In Azure
Create Linux VM In Azure Portal
how to create a vm in azure portal step by step

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

Step-4: Click on the Download private key and create resource button to download the key details that you need while connecting the virtual machine.

Create Linux VM In Azure

Step-5: It will take a few minutes and then will show you that Your deployment is complete. Click on the Go to Resource button to navigate to the Linux Virtual Machine that you have created.

How to create Linux Virtual Machine In Azure

Create Linux VM Using Azure CLI

You can easily create a linux virtual machine using Azure CLI by using the below steps.

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

az group create --name demoRsgGroup --location eastus

Once, you will execute the above command, you will get the output like 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"
}

Step-2: Now, execute the below 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 able to see it as below

Create Linux VM Using Azure CLI
az vm create

Once You will execute the above command, you will get the output like 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 can able to see the below Azure Linux VM created successfully.

How To Create Linux VM Using Azure CLI

Command To Create Virtual Machine In Azure

You can use below command in Azure CLI to create the Azure Virtual Machine.

az vm create --resource-group Resource Group Name  --name VM Name --image Win2016Datacenter --admin-username User Name --admin-password "Your Password" --location Location Name

Or,

New-AzVM

PowerShell command to create VM in Azure is as below. Refer to the above section for the complete details.

New-AzureRmVM -ResourceGroupName $vmresourceGroup -Location $location -VM $vmConfiguration

az vm create

You can use the az vm create command to quickly create an Azure Virtual machine using Azure CLI.

Syntax:

The syntax is as below

az vm create --resource-group Resource Group Name  --name VM Name --image Win2016Datacenter --admin-username User Name --admin-password "Your Password" --location Location Name

Example:

Consider the below example

az vm create --resource-group myRsgGroup --name TSINFOVM2 --image Win2016Datacenter --admin-username rajkishore --admin-password "[email protected]" --location eastus

In the above example.

  • myRsgGroup — The name of the Resource Group.
  • TSINFOVM2 — Virtual machine name.
  • Win2016Datacenter — Image name.
  • rajkishore–The local admin username for the VM.
  • [email protected] –The local admin password for the Virtual Machine.
  • eastus — The location name.

You may like following Azure tutorials:

Conclusion

In this Azure tutorial, we have discussed on the below topics:

  • How to Create Azure VM (Virtual Machine)
  • Virtual machine in azure
  • How To Create Free Virtual Machine In Azure
  • How to create a windows virtual machine (VM) in Azure
  • Create an Azure virtual machine by using PowerShell
  • Azure Create VM PowerShell
  • Create a free virtual machine in the Azure
  • How to create a free virtual machine in the Azure
  • Virtual machine in azure
  • How to create an Azure virtual machine by using PowerShell
  • How To Create Free Virtual Machine In Azure
  • Azure Create VM PowerShell
  • How To Create A Virtual Machine Using Azure CLI
  • How To Create Linux VM In Azure
  • How To Create Virtual Machine In Azure Step By Step
  • Create Linux VM Using Azure CLI
  • Command To Create Virtual Machine In Azure
  • az vm create

Hope you have enjoyed this article !!!