none
How to connect a new VM to an existing VM with Powershell RRS feed

  • Question

  • I see that I can "connect to an existing virtual machine" in the portal, as opposed to creating a standalone virtual machine. How can I do that via powershell? I only see that the New-AzureVM command allows you to create a VM in a new cloud service, or in an existing cloud service. But I if I try to use that and point it to an existing cloud service that has a copy of my VM running already, it gives me an error, saying "The specified deployment slot Production is occupied".

    Is there a different command that I'm missing?

    • Moved by Flavio Muratore [MSFT] Tuesday, November 13, 2012 5:09 PM (From:Windows Azure Virtual Machines for Windows)
    Tuesday, November 13, 2012 4:28 PM

All replies

  • Please let me know if this is what you are looking for.

    How to create an IaaS VM on an existing cloud Service?

    It can be done using PowerShell.

    The command below creates a VM on an existing cloud service.

    New-AzureVMConfig -Name VMNAME -InstanceSize ExtraSmall -ImageName MSFT__Win2K8R2SP1-Datacenter-201208.01-en.us-30GB.vhd | Add-AzureProvisioningConfig –Windows –Password P@ssw0rd | New-AzureVM –ServiceName Existingcloudservicename

    If you need to add to a subnet:

    The command below creates a VM on an existing cloud service and adds it to a specified subnet on the Vnet for that cloud service.

    Note: subnet name is case sensitive.

    New-AzureVMConfig -Name VMNAME -InstanceSize ExtraSmall -ImageName MSFT__Win2K8R2SP1-Datacenter-201208.01-en.us-30GB.vhd | Add-AzureProvisioningConfig –Windows –Password P@ssw0rd | Set-AzureSubnet SUbnetNAme | New-AzureVM –ServiceName ExistignCloudServiceName


    Flavio Muratore Sr. Support Escalation Engineer Windows Azure Technical Support

    Tuesday, November 13, 2012 4:34 PM
  • No, as I said I see that I can create a VM in an existing cloud service, but that creates a Standalone VM. I want to create many VM instances in the same existing cloud service. But after the first instance, this command fails saying that there is already something in that Production slot.
    Tuesday, November 13, 2012 4:46 PM
  • Rock,

    The Virtual Machines service is our IaaS offering (AKA Persistent VMs. Using IaaS they VMs will always be single instance. To create multiple instance of a virtual machine you need to use Cloud Services to deploy VM Worker Roles and VM Web Roles (PaaS).

    More information: http://msdn.microsoft.com/en-us/library/windowsazure/gg432976.aspx

    This forum is to provide support for IaaS Virtual Machines only. This may be the forum you are looking for: http://social.msdn.microsoft.com/Forums/en-US/windowsazuredevelopment/


    Flavio Muratore Sr. Support Escalation Engineer Windows Azure Technical Support

    Tuesday, November 13, 2012 4:55 PM
  • Unless I'm confused, I can do what I want from the portal, just not from Powershell. I can create a new VM in the portal, select my image, set the configuration values, then the next page asks if I want to create a standalone or connected VM. If I select connected, then I choose the cloud service that has my first instance, and if I continue it will create a new instance of my VM in that cloud service that already had an instance. In this way I can get multiple VM instances, and that's what I want to do via Powershell.
    Tuesday, November 13, 2012 5:02 PM
  • Rock,

    no doubt you are using a PaaS. I am moving your thread to the correct forum.


    Flavio Muratore Sr. Support Escalation Engineer Windows Azure Technical Support

    Tuesday, November 13, 2012 5:08 PM
  • GRRRRRRRRRR, no I am not. Are you reading the post?

    I create a virtual machine in Azure, based on the Windows 2012 OS. I installed and configured some software. I captured and persisted that image. Now if I create a virtual machine in the portal from my captured image, I have the option to create a standalone virtual machine, or a connected virtual machine. I can create a connected virtual machine which uses the same cloud service as my original virtual machine is running in. I just did it. All I want to know is if/how it can be done from Powershell.

    Tuesday, November 13, 2012 5:29 PM
  • Rock,

    I apologize if I did not understood your question correctly. The command to deploy a new Azure VM on an existing cloud service is below. You can specify your custom image on the -ImageName paramenter. On the example we are using a standard image from the galley.

    The command below creates a VM on an existing cloud service.

    New-AzureVMConfig -Name VMNAME -InstanceSize ExtraSmall -ImageName MSFT__Win2K8R2SP1-Datacenter-201208.01-en.us-30GB.vhd | Add-AzureProvisioningConfig –Windows –Password P@ssw0rd | New-AzureVM –ServiceName Existingcloudservicename

    If you need to add to a subnet:

    The command below creates a VM on an existing cloud service and adds it to a specified subnet on the Vnet for that cloud service.

    Note: subnet name is case sensitive.

    New-AzureVMConfig -Name VMNAME -InstanceSize ExtraSmall -ImageName MSFT__Win2K8R2SP1-Datacenter-201208.01-en.us-30GB.vhd | Add-AzureProvisioningConfig –Windows –Password P@ssw0rd | Set-AzureSubnet SUbnetNAme | New-AzureVM –ServiceName ExistignCloudServiceName


    Flavio Muratore Sr. Support Escalation Engineer Windows Azure Technical Support

    Tuesday, November 13, 2012 7:33 PM
  • Let's try it this way. I can run your first command to get my VM started in an existing cloud service. Now once that is going, if you go to the portal, start a new VM, and go through the steps, you come to the step shown below. In this step, I can choose to Connect to an existing VM. If I select this, I can then select the cloud service that has the VM running (that your command created). When I finish this in the portal, I get a new VM started from the same VM image. So now I have 2 VMs running in that cloud service.

    The problem is that if instead of using the portal, I use your command to try to create this second VM, the script gives an error saying that there is already something in the cloud service's Production slot. So I'm guessing the command is trying to use the Standalone option instead of the Connect option. So I want to know if I can run a PS command to create a VM that is connected to the first/existing VM in the cloud service.


    • Edited by Rock2000 Tuesday, November 13, 2012 8:01 PM
    Tuesday, November 13, 2012 7:59 PM
  • Rock,

    I think now I understand. The command I posted should create the VM on an existing Cloud Service, I have used it myself for that purpose a number of times. Since you are getting an error when running that command we need to investigate further.

    Can you post the exact command line you are using here on the forum? You can change the cloud service name, etc,, to keep privacy.


    Flavio Muratore Sr. Support Escalation Engineer Windows Azure Technical Support

    Tuesday, November 13, 2012 8:33 PM
  • This is the script that I basically found to use.

    $subID = "<ID>"
    $thumbprint = "<Thumb>"
    $myCert = Get-Item cert:\\CurrentUser\My\$thumbprint
    Set-AzureSubscription –SubscriptionName '<sub>' -SubscriptionId $subID -Certificate $myCert
    Set-AzureSubscription -SubscriptionName 'Sub' -CurrentStorageAccount '<store>'

    $imgName = “<myCustomImage>”

    #Setup the VM DNS settings
    $advmIP = “<AD IP>”
    $advmName = “<AD computer>”
    $dns1 = New-AzureDns -Name $advmName -IPAddress $advmIP

    #Setup the VM config
    $vmName = "comp1"
    $adminPassword = “<pwd>”
    $domainPassword  = “<pwd>”
    $domainUser = "<user>"
    $FQDomainName = "domain.me.com"
    $advm1 = New-AzureVMConfig -Name $vmName -InstanceSize Small -ImageName $imgName | Add-AzureProvisioningConfig -WindowsDomain -Password $adminPassword -Domain 'domain' -DomainPassword $domainPassword -DomainUserName $domainUser -JoinDomain $FQDomainName

    #Create the VM
    $serviceName = "<cloudService>"
    $affinityGroup = "eusa"
    $adVNET = "my-vm-net"

    New-AzureVM -ServiceName $serviceName -VMs $advm1 -DnsSettings $dns1 -VNetName $adVNET

    If I run this when I have no VMs yet, it works and creates the first VM in the cloud service. Now I want to basically run this again, just changing the $vmName to a new computer name. But since there is already a VM running in the cloud service, the PS commands give me an error telling me that there is something running in Production. So the commands are just trying to deploy a Standalone VM, but I need a command that will deploy a Connected VM now.

    Tuesday, November 13, 2012 8:45 PM
  • I believe the problem is that you cannot specify the -VNetMame when adding a new VM to an existing cloud service. All VMs in the cloud service share the same -VNetName.

    If you could test running the command I posted "as is" only modifying the purple parts and not adding or removing anything else it should work.

    You can then delete the test VM and on your script you most likely have to remove the -VNetName parameter when running it on a cloud service that already have a VM. Please note that if there is not VMs in the cloud service then -VNetName will be required.

    New-AzureVMConfig -Name VMNAME -InstanceSize ExtraSmall -ImageName MSFT__Win2K8R2SP1-Datacenter-201208.01-en.us-30GB.vhd | Add-AzureProvisioningConfig –Windows –Password P@ssw0rd | New-AzureVM –ServiceName Existingcloudservicename


    Flavio Muratore Sr. Support Escalation Engineer Windows Azure Technical Support

    Tuesday, November 13, 2012 8:57 PM
  • I get the same error with your script. If I run the script with no VMs in my cloud service, then the script works and I get the first VM. If I run your script again, with a different VMNAME, I get the same error that says "the specified deployment slot Production is occupied."
    Tuesday, November 13, 2012 10:19 PM
  • Have you tried re-creating the cloud service? There is a remote chance you are running on an issue with a Cloud Service that failed to deploy correctly.


    Flavio Muratore Sr. Support Escalation Engineer Windows Azure Technical Support

    Tuesday, November 13, 2012 10:25 PM
  • I recreated the service and got the same error. It doesn't seem like a bug. The error message is correct, in the sense that I have a VM already occupying that slot. So I think this command is just written to create a Standalone VM, and not handle the Connected case. Or at least with these parameters that's all it seems to do.
    Wednesday, November 14, 2012 1:30 PM
  • I'm too facing the same problem.. Is there any solution for it???
    Thursday, November 29, 2012 9:29 AM
  • It doesn't seem like it, although I gave up looking as the Azure IaaS seems very weak at this point.
    Friday, November 30, 2012 6:32 PM
  • I am also seeing this problem -- with the same script I can never add a VM to an existing service. Same error about a VM already occupying that slot. 

    Is there any resolution? This is very frustrating since it prevents me from automating my deployment. 

    Wednesday, December 26, 2012 11:36 AM
  • Clamanna,

    I just tested the following command once again, note this is the same command higher up on this thread.

    New-AzureVMConfig -Name MyTestVM1 -InstanceSize ExtraSmall -ImageName MSFT__Win2K8R2SP1-Datacenter-201210.01-en.us-30GB.vhd | Add-AzureProvisioningConfig –Windows –Password P@ssw0rd | New-AzureVM –ServiceName MyServiceName

    To see a list of available images you can issue a Get-AzureVMImage
    Change the "MyServiceName" to the name of your cloud service.

    Instead of running the script, could you try the command above? I expect it to work just fine.


    Flavio Muratore Sr. Support Escalation Engineer Windows Azure Technical Support


    Monday, December 31, 2012 4:45 AM
  • OMG, I am having this same issue, our scripts are identical. Holy Cow, a Year has gone by and this is still an issue? I am sure you moved on Rock? if not, WHAT DID YOU DO?!?!?!?
    Monday, October 14, 2013 9:19 PM
  • But, how do we run this against a Cloud Service that already has a VM instance in it?
    Monday, October 14, 2013 9:20 PM
  • Hi the way to add a VM to an existing cloud service is to NOT specify the location or affinity group !  Not really obvious at all.  Did a bit of searching on this and that worked. 

    Take out the affinity group, and subnet, just specify the service name.

    This article explains it much better.. from http://michaelwasham.com/windows-azure-powershell-reference-guide/windows-azure-virtual-machines-with-powershell-basics/

    "Passing -Location or -AffinityGroup tells the cmdlet you want it to create the cloud service

    • Not passing -Location or -AffinityGroup tells the cmdlet that you want it to create the virtual machine in an existing cloud service"

    Good luck !

    Mitesh


    Mitesh Chauhan MCDBA - MCSA

    Friday, November 1, 2013 11:19 PM