Write Azure code to create a VM

Start

To create a virtual machine in Azure using the Azure CLI, you can use the following code:

az group create --name myResourceGroup --location eastus az vm create \ --resource-group myResourceGroup \ --name myVM \ --image UbuntuLTS \ --generate-ssh-keys

This code creates a resource group named myResourceGroup in the eastus location, and then creates a virtual machine named myVM using the latest version of Ubuntu as the image. It also generates SSH keys for the virtual machine. To create a virtual machine in Azure using PowerShell, you can use the following code:

$resourceGroupName = "myResourceGroup" $location = "eastus" $vmName = "myVM" New-AzResourceGroup -Name $resourceGroupName -Location $location $vm = New-AzVMConfig -VMName $vmName -VMSize Standard_B1s $vm = Set-AzVMOperatingSystem -VM $vm -Linux -UbuntuOSVersion 18.04-LTS $vm = Set-AzVMSourceImage -VM $vm -PublisherName Canonical -Offer UbuntuServer -Skus 18.04-LTS -Version latest $vm = Add-AzVMNetworkInterface -VM $vm -Id $nic.Id New-AzVM -ResourceGroupName $resourceGroupName -Location $location -VM $vm

This code creates a resource group named myResourceGroup in the eastus location, and then creates a virtual machine named myVM using the latest version of Ubuntu as the image.Both of these examples create a basic virtual machine with default settings. You can customize the virtual machine by specifying additional options such as the size of the machine, the type of storage to use, and the username and password for the machine. For more information, you can consult the Azure documentation.

Previous Story

Popular Linux commands

Next Story

Write Powershell code to scan for viruses