VMware Cloud Community
devu1
Contributor
Contributor
Jump to solution

Power on VM after Creation

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?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
devu1
Contributor
Contributor
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
devu1
Contributor
Contributor
Jump to solution

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?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
devu1
Contributor
Contributor
Jump to solution

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.

0 Kudos