Deploying A Virtual Machine Using Azure CLI 2.0

The Azure CLI 2.0 is Azure's new command line experience for managing Azure resources. It can be either used in the browser itself with Azure Cloud Shell or you can install it on macOS, Linux, and Windows and run it from the command line. It is optimized for managing and administering Azure resources from the command line, and for building automation scripts that work against the Azure Resource Manager.

In this article, I will show you how to create a Virtual Machine using Azure CLI. You can launch the Cloud Shell by clicking the icon on the top of the Azure portal.

 

On launching for the first time, you will get a window at the bottom to select the environment. Here, I am selecting Bash for this demo.

Now, it will prompt for creating a storage account to persist your files from Shell session.

So, what happens here is like when you spin up a Cloud Shell in the background, Microsoft is going to stand up or initiate a container for you and you're going to be able to interact with that container and it's going to have the CLI installed in it. Clicking on "Create Storage" button will build a resource group with the storage account inside of it, and then, it'll launch a container for me. After initializing, you are ready to go.

CLI works in a way that you have to start with an az command followed by subcommands. An az --help command will help you to get a list of commands possible, the help command can also be used with subcommands also. For example, if we want subcommands of group section, you can have an az group --help command.

Let us create a resource group first. The syntax is as follows.

az group create -n ResourceGroupName -l Location

So here, I want to create a Resource Group at South East Asia.

This will give the result for your action in JSON format and you can check the resource group from the portal.

Now, we have to add resources to this group that is a Virtual Machine. For this demo, I am using a Windows Server 2016 Data Center-based VM using the az VM create command and add it to the same "CLIResourceGroup" resource group that we created before. We are going to add a no-wait argument as it will asynchronously create the virtual machine. Else, it will kind of tie up my prompt and it'll wait a couple of minutes while it's building the VM before I can continue working. You will be prompted for giving a password. Don’t get worried if what you are typing is not getting reflected there. Just type your password.

Now, if you check the resource group in the portal, you can see the new VM is being deployed.


Similar Articles