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
#SET USERNAME
$VMUser = "vmadmin"
#SET PASSWORD
$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
Processing…
Success! You're on the list.
Whoops! There was an error and we couldn't process your subscription. Please reload the page and try again.
Comments
One response to “Create an Azure Linux VM Using 5 Lines of PowerShell Code”
this is great – question how to i manual set the vnet/subnet?