Automation

 View Only
  • 1.  Power on VM after Creation

    Posted Sep 11, 2015 09:14 PM

    I'm trying to power on a VM asynchronously after creation. I don't want to spawn jobs or wait for a task to finish. Is this possible?



  • 2.  RE: Power on VM after Creation
    Best Answer

    Posted Sep 12, 2015 08:23 AM

    You didn't say how you create the new VM, from scratch or as a clone ?

    Anyway, afaik there is currently no cmdlet switch to let you specify that a cloned VM shall be powered on after creation.

    When you use the underlying API (CloneVM_Task) you have a property (poweron) in the VirtualMachineCloneSpec object, that lets you specify this.

    In summary, not with any of the current cmdlets.

    With the API Method you can define an automatic poweron with the clone method.



  • 3.  RE: Power on VM after Creation

    Posted Sep 14, 2015 02:14 PM

    I'm using a New-VM in a PowerShell function.

    New-VM -Name $($ServerAction.vmName) -Template $($ServerAction.Template) -OSCustomizationSpec $($ServerAction.OSCustomSpec) -Datastore $($ServerAction.DatastoreCluster) -ResourcePool $($ServerAction.ResourcePool) -Location $($ServerAction.Location) -Notes $($Description) -RunAsync



  • 4.  RE: Power on VM after Creation

    Posted Sep 14, 2015 07:06 PM

    Then I'm afraid you will have to revert to the API if you want the VM to power on automatically.

    But the alternative is to pipe ('|') the result of the New-VM cmdlet you are using to the Start-VM cmdlet.



  • 5.  RE: Power on VM after Creation

    Posted Sep 14, 2015 07:15 PM

    Won't Start-VM fail if the VM is still being cloned from template? If I pipe to Start-VM, I assume I can't create the VMs asynchronously, correct?



  • 6.  RE: Power on VM after Creation

    Posted Sep 14, 2015 08:31 PM

    Yes, you'll have to drop the RunAsync (missed that switch in your line of code).

    But why are you using the RunAsync here, does the actual cloning from a template take that long ?

    Remember the customisation will only start when the VM is powered on.

    You can of course also monitor the Task that was returned when you launched New-VM with the RunAsync switch.

    You can do this with the Wait-Task cmdlet, or you can check the State of the Task

    See   Re: Script to wait for Clone Task to complete



  • 7.  RE: Power on VM after Creation

    Posted Sep 14, 2015 08:40 PM

    The cloning takes about 10-20 minutes per VM depending which physical datacenter I'm sending it to. That's a long time to have the shell hanging out while 10 VMs are created synchronously. I'm thinking the API will be my best bet for now. I had the wait-task working but didn't want to have to wait for each VM. I really appreciate your help and will touch base on the API once I look it over and test.