Windows Azure PowerShell – Create two virtual machines in the same cloud service

I have created this post to show how to create two virtual machines in the same cloud service.  There seems to be some confusion and it is not clear in the documentation on how to do this.   If you use the standard scripts to create your first VM and then modify it for the second VM an error occurs as the New-AzureVM script tries to create the same cloud service again which of course it can not do.

This results in the following error shown below in the troubleshooting section.

How to Create Two VMs In The Same Cloud Service

Here is the full script to help you get up and running.  I know there are more elegant ways of doing much of this but I wanted to get the basics in so it is easy to see how it is working exactly.

The cloud service is tied to the VNET and affinity group and hence there is no need to specify these parameters for subsequent VM creations.  The script below uses pre created Affinity Group, Storage account and Vnet..

The following example script also joins the virtual machines to the domain demo.local. which also exists in the same virtual network.

# Created by Mitesh Chauhan - - December 2013.
  $mysubscriptionName   = 'Visual Studio Premium with MSDN'
# Set Affinity Group - This specifies that resources (VMs, storage etc) created in the Affinity Group are geographically close to one another to decrease network latency.
  $myAffinityGroupName  = 'NorthEuropeAffinityGroup'
#Your Virtual Network Name
  $myVnetName = 'BISkyVnet'
#Availability Set Names - Create these to ensure your service tiers are resilient and are created in different fault and update domains in the Azure DC
  $AvailabilitySetName = 'IISAVSet'
# Cloud Service Name - Use cloud services to group your VMs and for load balancing.
  $CloudService = 'IISCloudSVC1'
# Domain Controller VM Name
  $DC1VMName = 'MyCloudDC1'
  # Member Server Name
  $Servername = 'IISVM4'
  $server2name = 'IISVM3'
#Set storage name
$StorageAccountName = 'bistorageblob'
#Subnet Name
  $Subnetname = 'SPapp2'
  $subnet2name = 'SPapp3'
#set local admin and user accounts - Same password for local and domain admin, not for production.
  $Adminusername = 'AzureAdmin'
  $Adminpassword = 'Manager99'
#Set Azure Gallery Image Paths
  $ws2012 = ''
  $ws2012r2 = ''

Import-Module ‘C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1’
Set-AzureSubscription $mysubscriptionName -CurrentStorageAccountName $storageaccountname
Select-AzureSubscription $mysubscriptionName

#Deploy the 1st Member Server in a virtual network
$Servername = New-AzureVMConfig -name $Servername -InstanceSize “Small” -ImageName $ws2012R2 -AvailabilitySetName $AvailabilitySetName |
Add-AzureProvisioningConfig -adminusername $Adminusername -WindowsDomain -Password $Adminpassword -Domain “demo” -DomainUserName $Adminusername -DomainPassword $AdminPassword -JoinDomain “demo.local” |
Add-AzureDataDisk -CreateNew -DiskSizeInGB 128 -DiskLabel “FDrive” -LUN 0 ` | Set-AzureSubnet -SubnetNames ‘SPapp1’

New-AzureVM -ServiceName $CloudService -VMs $Servername -AffinityGroup $myAffinityGroupName -VNetName ‘BISkyVnet’ -WaitForBoot

#Create Second VM in same cloud service
$Servername = New-AzureVMConfig -name $Server2name -InstanceSize “Small” -ImageName $ws2012R2 -AvailabilitySetName $AvailabilitySetName |
Add-AzureProvisioningConfig -adminusername $Adminusername -WindowsDomain -Password $Adminpassword -Domain “demo” -DomainUserName $Adminusername -DomainPassword $AdminPassword -JoinDomain “demo.local” |
Add-AzureDataDisk -CreateNew -DiskSizeInGB 128 -DiskLabel “FDrive” -LUN 0 ` | Set-AzureSubnet -SubnetNames ‘SPapp2’

New-AzureVM -ServiceName $CloudService -VMs $Servername -WaitForBoot


Thank you for reading this and hopefully you found this useful !? If you did it would be great to hear from you.  If you have suggestions for other articles please let me know and I will try and publish.


The following errors are reported when trying to create the second VM using the standard script and specifying the affinity group and vnet.


“New-AzureVM : ConflictError: The specified DNS name is already taken.”


Azure PowerShell : – Error  “ConflictError: The specified DNS name is already taken.

The resolution to this is to use the New-AzureVM (after cloud creation) without specifying the affinity group or network name.

Here is the script AFTER the new-azurevmconfig section which actually creates the new cloud service and first VM.

New-AzureVM -ServiceName $CloudService -VMs $Servername -AffinityGroup $myAffinityGroupName -VNetName ‘BISkyVnet’ –WaitForBoot

Here is the script to create the second server in the same cloud service.

New-AzureVM -ServiceName $CloudService -VMs $Servername -WaitForBoot

Thank you for taking the time to read this article and I hope it was useful.


About Mitesh Chauhan
Mitesh Chauhan, Azure Cloud Solutions Architect. This is my blog where I share articles and thoughts on IT Infrastructure and architecture. The topics I am most passionate about are Implementation and architecture of rock solid Cloud Infrastructure based around SQL Server and Windows Server mainly using Microsoft Azure. MCTS - Azure Architecture MCTS - Azure Implementation MCSE Server Infrastructure (Windows Server 2012) , MCITP SQL Server 2008, Togaf Certified, Prince 2 Practitioner.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: