Create VM in Azure with 3 different methods [Step-by-Step]

Sahil Hulage


Overview on Azure Resource Manager

  • Azure Resource Manager (ARM) enables you to work with the different components (referred to as resources in Azure terminology) in your application solution as a group.
  • This gives us the ability to deploy, update or delete all the resources for your application in a single operation if needed.
  • Another very useful feature of ARM is that it allows us to apply tags to related resources. This in turn, allows you to better understand your organization’s billing by being able to costs associated with a group of resources sharing the same tag.

In this article, we will discuss three of the most popular methods Azure administrators use to interact with Azure Resource Manager. We will also be including practical demonstrations of using these methods to step by step create virtual machine in Azure Cloud using each of the methods.


Different Azure Terminologies

Before we move on to the discussion about the different methods, there is some Azure related terminology that you should be familiar with.

  • Resource - A manageable item that is available through Azure. Some common resources are a virtual machine, storage account, web app, database, and virtual network, but there are many more.
  • Resource group - A container that holds related resources for an Azure solution. The resource group can include all the resources for the solution, or only those resources that you want to manage as a group. You decide how you want to allocate resources to resource groups based on what makes the most sense for your organization.
  • Resource provider - A service that supplies the resources you can deploy and manage through Resource Manager. Each resource provider offers operations for working with the resources that are deployed. Some common resource providers are Microsoft.Compute, which supplies the virtual machine resource, Microsoft.Storage, which supplies the storage account resource, and Microsoft.Web, which supplies resources related to web apps.


Different methods to create VM in Azure

In this article we’ll be exploring the following three methods to create VM in Azure

  • The Azure Portal
  • Azure CLI
  • Azure PowerShell


Method 1: Create VM using the Azure portal

The Azure portal is our login portal to the Azure cloud and this is where we can create and modify our resources. To login to the Azure portal open the URL and enter your credentials.

Once done, you would see the following page which is you home page.

Create VM in Azure with 3 different methods (Step-by-Step)
Azure Portal


Now that we’ve familiarized ourselves with the Azure portal, let’s create a virtual machine using the portal.


Step 1: Create new VM using the Azure portal

Click on Virtual Machines under the Azure Services section in Azure home page.

Create VM in Azure with 3 different methods (Step-by-Step)
Create Virtual Machine using Azure Portal


From here click on create and click on Virtual Machine.

Create VM in Azure with 3 different methods (Step-by-Step)


Step 2: Enter VM details

In the below menu. Keep all the defaults and type in a suitable name for your VM.

Create VM in Azure with 3 different methods (Step-by-Step)
Provide VM Details

We are using and Ubuntu image for the purpose of this demonstration. Since this is a basic VM creation demo, we’ll skip the advanced options. Now click on Review + create.


Step 3: Confirm VM details

In the next windows, the VM size and corresponding pricing details are displayed. Also, the subscribers’ information name, email and phone number fields are displayed.

Create VM in Azure with 3 different methods (Step-by-Step)
Confirm VM Details


Towards the bottom left of the window, you’ll see a create button. You can also click on the previous button next to the create button in case you’d like to modify some settings. In our case, we’ll click on create. After clicking the create button, you’ll be prompted to download a private key as shown below.

Create VM in Azure with 3 different methods (Step-by-Step)
Generate KEY Pair


Click on this button to complete the creation of your virtual machine. The virtual machine creation will take a couple of seconds. While the VM is being deployed, you’ll be able to see the status of the related resources as they get deployed as well.

Create VM in Azure with 3 different methods (Step-by-Step)
Deployment Status


This will also download a ssh public key to your downloads folder. You need to use this key to connect to your virtual machine once it boots up since password based authentication is not permitted by default in Azure VMs.


Step 4: Confirm VM deployment

Once the VM deployment completes successfully, we’ll be shown the below message and a button towards the end named Go to resource. Clicking on this button will navigate you to the VM management window for the VM that we just created.

Create VM in Azure with 3 different methods (Step-by-Step)


The management window will display a breadth of information including the public IP address that we may use to connect to the VM via ssh.

Create VM in Azure with 3 different methods (Step-by-Step)



Method 2: Create VM with Azure CLI (bash on cloud shell)

Earlier in the article, we explained how to start the Azure Cloud Shell command line interface and now we will use it to interact with Azure Resource Manager by creating a virtual machine.

We can use the Azure CLI to manage our Azure resources without having to log in to the Azure portal. For Linux system admins who are used to working with the command line, this tool would prove to be very helpful. Although, we can install an SDK for Azure CLI on our local system, we can also use it via the Azure cloud shell. For the purpose of our demonstration, we’ll be using Azure CLI via Cloud Shell. When we select bash while launching Cloud shell, we are dropped into a command prompt as shown below.

Create VM in Azure with 3 different methods (Step-by-Step)

From within this terminal, we can now execute our Azure CLI commands.


Step 1: Determine Resource Group name

The resource group is a logical container where we group our Azure resources. All our Azure resources must belong to a resource group. Although we can type in the name of the resource group manually, in this example, we’ll find it out programmatically using an Azure CLI command and assign the result to a variable. The below Azure CLI command list the resource group that we are currently using.

az group list --query [].name --output tsv

Sample Output:
Create VM in Azure with 3 different methods (Step-by-Step)

The above command assigns the output of the Azure CLI command to a variable named RG. Here’s a quick explanation of what the command is doing

  • The “az group list” command will print information about the currently active resource group in JSON format.
  • The --query sub-command can be used to filter out the result and [].name will print only the name of the resource group.
  • Since this name is still in JSON format, we modify the output format to tsv so that we may remove the additional braces encompassing the initial JSON output and use the output directly inside a variable.

We can view the contents of the variable by just printing it out using echo command. Most commands found in a Linux distro will work in this interface.


Step 2: Create VM

To create a virtual machine, we will use the following command:

cloud@Azure:~$ az vm create --resource-group $RG --name azuredemo --image UbuntuLTS --admin-username demouser --generate-ssh-keys

SSH key files '/home/cloud/.ssh/id_rsa' and '/home/cloud/.ssh/' have been generated under ~/.ssh to allow SSH access to the VM. If using machines without permanent storage, back up your keys to a safe location.

It is recommended to use parameter "--public-ip-sku Standard" to create new VM with Standard public IP. Please note that the default public IP used for VM creation will be
changed from Basic to Standard in the future.

  "fqdns": "",
  "id": "/subscriptions/964df7ca-3ba4-48b6-a695-1ed9db5723f8/resourceGroups/1-c83bd51a-playground-sandbox/providers/Microsoft.Compute/virtualMachines/azuredemo",
  "location": "centralus",
  "macAddress": "00-0D-3A-90-63-B9",
  "powerState": "VM running",
  "privateIpAddress": "",
  "publicIpAddress": "",
  "resourceGroup": "1-c83bd51a-playground-sandbox",
  "zones": ""

Sample Output:
Create VM in Azure with 3 different methods (Step-by-Step)

Here is a quick description of the arguments we used in the above command while creating the VM

  • --resource-group argument specifies the resource group within which this VM will reside. In our case, we provided the variable name that holds the name of the resource group.
  • --name argument denotes the name of the virtual machine.
  • --image argument specifies the OS image that we’d like to use. You can browse the Azure portal for a list of available images.
  • --admin-username argument will create a user inside the VM that will have super user privileges since it’s a common security measure in many environments to prevent direct root login.
  • --generate-ssh-keys will generate a pair of public-private ssh keys and save them in the home directory of the currently logged in user. These keys are important since they will be used for authentication.


Step 3: Verify connectivity to the VM

Once, our VM is created we can connect to it via ssh from within cloud shell itself as shown below
Create VM in Azure with 3 different methods (Step-by-Step)

In case you do not remember the public IP address of your VM, you can always query it form within the Azure CLI using the below command:

cloud@Azure:~$ az vm show -d --resource-group $RG --name azuredemo --query "publicIps" -o tsv


Method 3: Create VM Using Azure PowerShell

The third and final method to create VM is using Azure PowerShell.

This is essentially a set of PowerShell cmdlets that we use to interact with the Azure Resource Manager. Like the Azure CLI we can install Azure PowerShell cmdlets using an SDK or use it via the Azure Cloud shell. In our case, we’ll be using it via the Cloud shell. To switch between bash and PowerShell we just need to click the button on the top left of the Azure Cloud shell window that says bash and select PowerShell. This will drop us into an Azure PowerShell prompt. Or you can also select PowerShell at the prompt when you initially launch Azure Cloud Shell.

The Azure PowerShell prompt will appear as follows:

Create VM in Azure with 3 different methods (Step-by-Step)

Let us now create a VM using Azure PowerShell


Step 1: Determine Resource Group

Like our last example with Azure CLI, we’ll not use the resource group name directly and will instead determine it programmatically and store its value in a variable using the following command:


Sample Output:
Create VM in Azure with 3 different methods (Step-by-Step)

A great thing about Azure PowerShell is that it allows tab completion which means you don’t need to memorize lengthy commands.


Step 2: Create virtual machine

To create a virtual machine using Azure PowerShell we will use the New-AzVM cmdlet. We will provide the resource group name, the virtual machine name and the name of the image to use as arguments to the New-AzVM cmdlet as shown in the below command.

New-AzVM -ResourceGroupName $rg -Name azuredemo2 -Image Win2019Datacenter

Sample Output:
Create VM in Azure with 3 different methods (Step-by-Step)

Here we’ve used the Windows 2019 Datacenter edition as our VM image and named it azuredemo2. Once the command executes, we’ll be prompted to enter credentials for our admin user. After the VM build completes, the VM details will be displayed in JSON format as shown below.

Create VM in Azure with 3 different methods (Step-by-Step)


Step 3: Verify VM build

To check the status of the virtual machine, we can use the Get-AzVM -status command.

Get-AzVM -status

Sample Output:
Create VM in Azure with 3 different methods (Step-by-Step)

We can also use the Get-AzResource cmdlet to display information about VMs running in Azure.

Get-AzResource -ResourceType Microsoft.Compute/virtualMachines

Sample Output:
Create VM in Azure with 3 different methods (Step-by-Step)


To get the public IP information for the VM, we can issue the following command

Get-AzVM -ResourceGroupName $rg -Name ‘azuredemo2’ | Get-AzPublicIpAddress

Sample Output:
Create VM in Azure with 3 different methods (Step-by-Step)

To connect to the VM, we’d need to go to the Azure portal and download the corresponding RDP file for the VM and then use it to connect. This concludes our demonstration on using Azure PowerShell for interacting with the Azure Resource Manager. The PowerShell cmdlets being used might seem like difficult to remember but since PowerShell allows tab completion, using cmdlets becomes fairly easy leaving not much to memorize.



In this article, we discussed three different methods used to interact with the Azure Resource Manager and create Virtual Machine. As a newbie to Azure, we’d recommend using the Azure portal to manage your Azure resources as it will give a good feel of the Azure ecosystem allowing you to explore what Azure has to offer. Once you have achieved a certain level of familiarity with the myriad of Azure offerings, we encourage you to try out scripting the creation of Azure resources using your preferred method of choice be it Azure CLI or Azure PowerShell.



We’ve used the following resources while writing this article

Views: 255

Sahil Hulage

He possesses over 5 years of experience as a Cloud Consultant, specializing in Azure DevOps and CloudLinux. With his expertise, he implements and optimizes cloud solutions, ensuring seamless operations and efficient resource management. You can connect with him on LinkedIn.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to

Thank You for your support!!

Leave a Comment

GoLinuxCloud Logo

We try to offer easy-to-follow guides and tips on various topics such as Linux, Cloud Computing, Programming Languages, Ethical Hacking and much more.

Programming Languages