DevOps Basics: Quickly Creating Customized Azure Virtual Machines via PowerShell

In the previous post entitled DevOps Basics: Quickly Creating Azure Virtual Machines via PowerShell, the prescribed steps covered the ability to provision a simple configured single virtual machine. However, seldom does one size fit all.

What if more customization is required?

There is a secondary method that uses cmdlets to build a configuration object allowing for additional options to be added to the virtual machine during creation. Options that can be added include the following:

  • Active Directory domain join information
  • Endpoints
  • Data disks & configuration
  • Network configuration including instance level, reserved & static IP addresses

The following Windows PowerShell example creates virtual machine VM2 in CANITPRO-vms cloud service and configures endpoint 1433 via a open TCP port via the Add-AzureEndpoint cmdlet.

$adminUser = "[admin user name]"
$password = "[admin password]"
$serviceName = "CANITPRO-vms"
$location = "East US"
$size = "Small"
$vmName = "VM2"
$imageFamily = "Windows Server 2012 R2 Datacenter"
$imageName = Get-AzureVMImage |
                where { $_.ImageFamily -eq $imageFamily } |
                           sort PublishedDate -Descending |
                 select -ExpandProperty ImageName -First 1

New-AzureVMConfig -Name $vmName `
                  -InstanceSize $size `
                  -ImageName $imageName |

Add-AzureProvisioningConfig -Windows `
                            -AdminUsername $adminUser `
                            -Password $password |

Add-AzureDataDisk -CreateNew `
                  -DiskSizeInGB 10 `
                  -LUN 0 `
                  -DiskLabel "data" |

Add-AzureEndpoint -Name "SQL" `
                  -Protocol tcp `
                  -LocalPort 1433 `
                  -PublicPort 1433 |

New-AzureVM -ServiceName $serviceName `
            -Location $location

IT professionals can also utilize the Add-AzureProvisioningConfig cmdlet should further customization be required.  This cmdlet however, cannot be used in conjunction with the New-AzureQuickVM cmdlet. Futher detail surrounding the Add-AzureProvisioningConfig cmdlet will be covered in a future post.