How to create a VM in Azure CLI?

az vm create `
–resource-group myResourceGroup `
–name myVM –image win2016datacenter `
–admin-username Azureuser `
–admin-password myPassword12

 

To create a virtual machine (VM) in Microsoft Azure using Azure CLI, you can use the following steps:

  1. Open a terminal or command prompt.
  2. Make sure you have the Azure CLI installed. If not, you can download and install it from the official Azure CLI website: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli
  3. Log in to your Azure account using the following command:
    az login

    This command will open a web page where you can enter your Azure credentials.

  4. After logging in, choose the subscription where you want to create the VM:
    az account set --subscription <subscription_id>

    Replace <subscription_id> with the actual ID of your subscription.

  5. Use the following command to create a VM. Adjust the parameters according to your requirements:
    az vm create --resource-group <resource_group_name> --name <vm_name> --image <image_name> --admin-username <admin_username> --admin-password <admin_password> --size <vm_size>

    Replace <resource_group_name>, <vm_name>, <image_name>, <admin_username>, <admin_password>, and <vm_size> with your desired values.

    Here is a breakdown of the parameters:

    • <resource_group_name>: The name of the resource group where the VM will be created.
    • <vm_name>: The name of the virtual machine.
    • <image_name>: The name or ID of the VM image to use (e.g., “UbuntuLTS” or “WindowsServer”).
    • <admin_username>: The username for the VM’s administrative account.
    • <admin_password>: The password for the VM’s administrative account.
    • <vm_size>: The size of the VM (e.g., “Standard_D2s_v3”).

    After running this command, Azure will provision the VM in the specified resource group.

Remember to replace placeholders with your actual values, and you may need to adjust the command based on your specific requirements and the Azure region you are deploying to.