Quantcast
Channel: Category Name
Viewing all articles
Browse latest Browse all 10804

Create and pre-configure Azure virtual machines the easy way with PowerShell

$
0
0

There are multiple ways you can create virtual machines (VMs) that are hosted in Azure infrastructure services including portals, Visual Studio, programmatically, and at the command line.

If you’re an in-the-trenches IT pro, you want to not only create VMs easily but also pre-configure as many elements as possible during the VM’s provisioning so there’s less to do after the VM has been created.

A great example for Windows-based VMs is Active Directory (AD) domain membership. This can be easily done after the VM has been created, but wouldn’t it be easier for Azure to do during provisioning? Exactly.

To make it easy for you to create and pre-configure Azure VMs with Azure PowerShell, the following new topics are available:

Pre-configuration elements for Windows-based Azure VMs include:

  • Joining an existing AD domain
  • Adding one or more data disks
  • Specifying a static IP address (known as a static DIP)
  • Specifying a subnet and virtual network
  • Specifying membership in a load-balanced set

For additional pre-configuration options for Windows-based virtual machines, see the syntax for the Windows and WindowsDomain parameter sets in Add-AzureProvisioningConfig.

Pre-configuration elements for Linux-based Azure VMs include:

  • SSH key pairs
  • Adding one or more data disks
  • Specifying a static IP address (known as a static DIP)
  • Specifying a subnet and virtual network
  • Specifying membership in a load-balanced set

For additional pre-configuration options for Linux-based virtual machines, see the syntax for the Linux parameter set in Add-AzureProvisioningConfig.

For the less-than-comfortable PowerShell user, each topic takes you step-by-step through the process of building a command set that creates the VM with required settings and your optional pre-configuration settings. Each topic also takes a “fill-in-the-blanks” approach, in which some lines are there for you to fill in variable values, which then get executed within the appropriate commands.

For example, when specifying the virtual machine name and size, you start with this:

$vmname=""

$vmsize=""

$vm1=New-AzureVMConfig -Name $vmname -InstanceSize $vmsize -ImageName $image

You then fill in the VM name and instance size value (removing the < and > characters), resulting in:

$vmname="MONGO-WCOAST"

$vmsize="Medium"

$vm1=New-AzureVMConfig -Name $vmname -InstanceSize $vmsize -ImageName $image

Separating the variables from the commands makes the overall command set less error-prone. It is not the tightest PowerShell code, but is designed for ease of configuration, readability, and customization.

Here is one of the examples of a completed PowerShell command set to create and pre-configure a VM that:

  • Uses the Ubuntu Server 12.10 image
  • Has the name AZMYSQL1
  • Has an additional data disk of 500 GB
  • Has the static IP address of 192.168.244.4
  • Is in the BackEnd subnet of the AZDatacenter virtual network
  • Is in the Azure-TailspinToys cloud service
$family="Ubuntu Server 12.10"
$image=Get-AzureVMImage | where { $_.ImageFamily -eq $family } | sort PublishedDate -Descending | select -ExpandProperty ImageName -First 1

$vmname="AZMYSQL1"
$vmsize="Large"
$vm1=New-AzureVMConfig -Name $vmname -InstanceSize $vmsize -ImageName $image

$username="Admin397A"
$pass="3A#q291{Y"
$vm1 | Add-AzureProvisioningConfig -Linux -LinuxUser $username -Password $pass

$vm1 | Set-AzureSubnet -SubnetNames "BackEnd"

$vm1 | Set-AzureStaticVNetIP -IPAddress 192.168.244.4

$disksize=500
$disklabel="MySQLData"
$lun=0
$hcaching="None"
$vm1 | Add-AzureDataDisk -CreateNew -DiskSizeInGB $disksize -DiskLabel $disklabel -LUN $lun -HostCaching $hcaching

$svcname="Azure-TailspinToys"
$vnetname="AZDatacenter"
New-AzureVM –ServiceName $svcname -VMs $vm1 -VNetName $vnetname

Once you’ve created a command set for a VM that you intend to create over and over again, you can save it as a PowerShell script file (*.ps1) or turn it into an Azure automation runbook in the Automation section of the Azure Management Portal.

For more information, see Get Started with Azure Automation!

AzureVMsPS

Joe Davies
Senior Content Developer


Viewing all articles
Browse latest Browse all 10804

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>