Azure PowerShell: Provisioning Multiple VMs

To create new VMs for use with the Virtual Machines and Virtual Networks preview feature for Azure, you can use the Azure PowerShell Commands available at The specific commands to provision a VM are…

The examples on how to use this are typically as follows:

C:\PS>New-AzureVMConfig -Name "MyNewVM" -InstanceSize ExtraSmall -ImageName "MyImageName"
          | Add-AzureProvisioningConfig -Windows -Password $adminPassword `
          | New-AzureVM -ServiceName "MySvc2"


This is fine when deploying creating one Virtual Machine, however this can be slightly unreliable when you need to create multiple VMs in quick succession. I would often see that the VM I created was stopped, and the following error was shown:

“The server encountered an internal error. Please retry the request. The long running operation tracking ID was: [UNIQUEID]”.

To avoid errors, you can use the above commands in a different way to that specified in the examples, creating multiple configs, but only calling New-AzureVM once (passing it an array of configs), as well as giving the deployment a unique name. The example below illustrates this…

$vmConfig = New-AzureVMConfig -Name "MyVMName1" -InstanceSize "Small" -ImageName "MyImage.vhd" 
$vmDetails = Add-AzureProvisioningConfig -Windows -Password "password" -VM $vmConfig
$vmConfig2 = New-AzureVMConfig -Name "MyVMName2" -InstanceSize "Small" -ImageName "MyImage.vhd" 
$vmDetails2 = Add-AzureProvisioningConfig -Windows -Password "password" -VM $vmConfig2
New-AzureVM -ServiceName "MyService" -VMs @($vmDetails, $vmDetails2) -DeploymentName "MyUniqueDeploymentName"

Note, there is also some documentation of this available at (see the section on “Creating Multiple Virtual Machines”.


Written by Rob Nowik




Comments (0)

Skip to main content