1

I use a powershell script to create a virtual machine in azure.

The script goes like this :

$serviceName = 'nameOfTheService'
$vmName = 'nameOfTheVM'

$osDiskName = 'nameOfTheDisk'

$config = New-AzureVMConfig -Name $vmName -DiskName $osDiskName -InstanceSize $size | Add-AzureEndPoint -Name 'Remote Desktop' -LocalPort 3389 -PublicPort 3389 -Protocol tcp

New-AzureVM -ServiceName $serviceName -Location $location -VMs $config

First time runs just fine.

If I delete the VM and re-run the script, it says that "the specified DNS name is already take", wich is true because I did not deleted the cloud service.

Is there a way I can reuse the existing cloud service when creating the machine?

1 Answer 1

0

When you deploy several VMs to one CouldService, you only need to define AffinityGroup to the first VM you create, not the later ones.

#Create VM with a New Cloud Service 
New-AzureVM –ServiceName $cloudService -VMs $vmConfig -VNetName $virtualNetwork -AffinityGroup $affinityGroup
#Create VM into an existing Cloud Service
New-AzureVM –ServiceName $cloudService -VMs $vmConfig -VNetName $virtualNetwork 

Niraj Bhatt has an execellent blog post about this titled Windows Azure IAAS & PowerShell - 5 Important Tips.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .