Create an Azure Linux VM Using 5 Lines of PowerShell Code

In this blog post, I will show you how I create an Azure virtual machine using Azure PowerShell using 5 lines of code.

About the code

The five lines of code create the following:

  • Create a new Azure Resource Group.
  • Create a local user for the VM
  • Set the password for the local user.
  • Create a Linux VM called VMDOCKERHOST in the South East Asia region.
  • Configure the VM to use the B1ls instance size.

Run the Code

To run code, run the five line and you are done.

In my case,  I am using Cloud Shell.

#Create RG
New-AzResourceGroup -Name rg-dev-linux -Location southeastasia
$VMUser = "vmadmin"
$VMpassword = ConvertTo-SecureString "PASSWORD" -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($VMUser, $VMpassword);
#Deploy VM
New-AzVm -image CentOS -size Standard_B1ls -ResourceGroupName "rg-dev-linux" -Name "VMDOCKERHOST" -Location "Southeastasia" -OpenPorts 22 -Credential $Credential

Success! You're on the list.

1 thought on “Create an Azure Linux VM Using 5 Lines of PowerShell Code”

Comments are closed.