Creating virtual machines using Azure PowerShell cmdlets
You can create virtual machines using Azure PowerShell cmdlets, including advanced configuration options such as: network endpoints, data disks, and Active Directory domain join information. You have full control over the names and locations of the underlying VHD (virtual hard disk) files for the virtual machine during creation. Like the Azure cross-platform command-line tools, the Azure PowerShell cmdlets support most Azure resources for automation. The Azure PowerShell cmdlets only work on Windows clients.
There are two methods of creating a virtual machine using the Azure PowerShell cmdlets.
The first method is to use the New-AzureQuickVM cmdlet. This cmdlet allows you to provisiona single virtual machine with a simple configuration based on an image only. This cmdlet does not support instantiating a virtual machine from a disk. You also cannot specify additional endpoints, or create data disks during virtual machine creation.
The Windows PowerShell following example uses the New-AzureQuickVM cmdlet to create a virtual machine with the instance size set to Small. It is created in the contoso-vms cloud service in the West US region. The image name is retrieved using the Get-AzureVMImage cmdlet.
$adminUser = “[admin user name]”
$password = “[admin password]”
$serviceName = “contoso-vms”
$location = “West US”
$size = “Small”
$vmName = “vm1”
$imageFamily = “Windows Server 2012 R2 Datacenter”
$imageName = Get-AzureVMImage |
where { $_.ImageFamily -eq $imageFamily } |
sort PublishedDate -Descending |
select -ExpandProperty ImageName -First 1
New-AzureQuickVM -Windows `
-ServiceName $serviceName `
-Name $vmName `
-ImageName $imageName `
-AdminUsername $adminUser `
-Password $password `
-Location $location `
-InstanceSize $size
The second method uses a combination of cmdlets to build up a configuration object for the virtual machine. With this technique you can add additional options to the virtual machine at creation time such as data disks, endpoints, and Active Directory domain join information. The first cmdlet to call is New-AzureVMConig, which creates a local configuration object that can be passed to other Azure cmdlets that support the VM parameter either directly, or using the Windows PowerShell pipeline operator. With this method you can set operating system and data disk configuration (custom paths and file names), configure endpoints (including load-balanced), as well as advanced network features such as reserved, instance level, and static IP addresses.
The Windows PowerShell following example creates a Small virtual machine named vm2 in the contoso-vms cloud service. It also configures the new virtual machine to have an endpoint open for TCP port 1433 using the Add-AzureEndpoint cmdlet, and a 10 GB data disk attached using the Add-AzureData disk cmdlet.
$adminUser = “[admin user name]”
$password = “[admin password]”
$serviceName = “contoso-vms”
$location = “West 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
In the above example, the virtual machine configuration is created using the New-AzureVMConfig cmdlet, and passed to each of the cmdlets using the PowerShell pipeline operator. This can also be accomplished by storing the returned configuration in a variable and passing it with the VM parameter (Add-AzureEndpoint -VM $config), or by piping the returned variable itself to the cmdlet ($conig | Add-AzureEndpoint). Variations may show up on the exams so it is important to be familiar with each syntax. There are several additional cmdlets used in this example that are not available with New-AzureQuickVM. The Add-AzureProvisioningConig cmdlet is used to specify the configuration information needed when provisioning from an image such as machine name, and
the administrator user name and password. This cmdlet can modify the behavior of the virtual machine in several other ways. The Add-AzureDataDisk cmdlet is used to attach new empty disks, or attach existing data disks, to a virtual machine. The Add-AzureEndpoint cmdlet is used to create an input endpoint on the virtual machine. Input endpoints allow network trafic into the virtual machine on a specific port. This cmdlet can also be used to add load-balanced endpoints, and can attach access control lists.
To create the virtual machine using this technique you must pass the configuration object to the New-AzureVM cmdlet. The New-AzureVM cmdlet does the bulk of the work of creating the virtual machine with the passed in configuration. Table below shows the differences between the two approaches for creating virtual machines.
New-AzureQuickVM | New-AzureVMConfig and New-AzureVM |
---|---|
Windows and Linux supported | Windows and Linux supported |
Create only from image | Create from image or operating system disk |
Specify availability set name | Specify availability set name |
Specify subnet and virtual network | Specify subnet and virtual network |
Deploy to location or afinity group | Deploy to location or afinity group |
Deploy X509 certiicates | Deploy X509 certiicates |
Deploy SSH certiicates on Linux virtual machines | Deploy SSH certiicates on Linux virtual machines |
Specify Active Directory domain join information | |
Require admin password reset on first login | |
Create new or attach existing data disks | |
Configure endpoints (including internal and external load balancing) | |
Disable Windows Update | |
Specify the time zone | |
Specify static IP addresses | |
Specify reserved IP address of the cloud service/domain name |
This article is a part of 70-533 Implementing Microsoft Azure Infrastructure Solutions Prep course.
More Articles included in this course are

Custom domain for Azure website
Read More

SSL certificates for an Azure website
Read More

Azure Traffic Manager
Read More

Handler mappings configuration for an Azure website
Read More

Virtual applications and directories for an Azure website
Read More
Practice Tests in this course are

70-533 Implementing Microsoft Azure Infrastructure Solutions Practice Test 6
Read More

70-533 Implementing Microsoft Azure Infrastructure Solutions Practice Test 7
Read More
You must log in to post a comment.