VMware Cloud Community
fleeb
Contributor
Contributor
Jump to solution

new-vm and startvm together?

When you create a new virtual machine with the gui, you have the option to "power on virtual machine after completion". I can't find a way to do this with new-vm. It would be really handy.

The reason I ask is that I use a script to deploy hundreds of desktops to a remote desktop farm. I throttle the connections using wait-task based on the number of tasks that have been issued. Then I pipe in a start-vm command. It looks similar to this:

import-csv $filename | %{ new-vm with parameters and -runasync } | start-vm

What happens is all machines are created but the last few are not turned on. The error I get is that they reference a task that is no longer there. I believe this is happeneing because the script is calling start-vm before the machines are finished deploying.

Any ideas of a way around this, or to use new-vm to power on a machine after deployment?

(code attached)

Thanks,

Mike

0 Kudos
1 Solution

Accepted Solutions
kjb007
Immortal
Immortal
Jump to solution

This may be a bit overkill, but it looks like you're already keeping track of how many vm's you have to do, and you could keep track of how many you've done. Since you're running a wait-task and throttling your new-vm requests, when you get down to the last one, don't run async anymore? Which should give you time to wait for the previous vm's to all complete, and then start the final one when it's done cloning.

vExpert/VCP/VCAP vmwise.com / @vmwise -KjB

View solution in original post

0 Kudos
7 Replies
kjb007
Immortal
Immortal
Jump to solution

Maybe this is too simplified, but why not, use another array to associate vmnames to the task ID's? Then test the task ID's for completion or existence, and if complete, then you know which task finished with vm, and start that vm.

-KjB

vExpert/VCP/VCAP vmwise.com / @vmwise -KjB
0 Kudos
fleeb
Contributor
Contributor
Jump to solution

That's actually what we do, the only problem with this is that it waits for all the machines to deply (hundreds... so hours) and then powers them on after the fact. We would like EACH vm to power on when it finishes deploying so that it can finish sysprepping and be available as soon as possible.

Thanks, though!

0 Kudos
kjb007
Immortal
Immortal
Jump to solution

What about checking for the vm and attempting power-on in your if loop before the wait-task?

-KjB

vExpert/VCP/VCAP vmwise.com / @vmwise -KjB
0 Kudos
fleeb
Contributor
Contributor
Jump to solution

The issue is only with the last few VMs, and they don't finish deploying until the script is done. I guess I could say if its the last machine wait X amount, check again else wait more... Just seems like a hassle when the configuration exists in the gui.

0 Kudos
kjb007
Immortal
Immortal
Jump to solution

This may be a bit overkill, but it looks like you're already keeping track of how many vm's you have to do, and you could keep track of how many you've done. Since you're running a wait-task and throttling your new-vm requests, when you get down to the last one, don't run async anymore? Which should give you time to wait for the previous vm's to all complete, and then start the final one when it's done cloning.

vExpert/VCP/VCAP vmwise.com / @vmwise -KjB
0 Kudos
fleeb
Contributor
Contributor
Jump to solution

You've actually hit the head on the nail. I actually came up with a solution a little earlier... I just add an extra field in my CSV that is "islastvm". If its true I run async, if not, I don't.

It is not as pretty as I would have hoped, but it is good enough. Thanks for the assistance!

0 Kudos
kjb007
Immortal
Immortal
Jump to solution

No problem, glad to help.

-KjB

Don't forget to mark the question answered and give helpful/correct points.

vExpert/VCP/VCAP vmwise.com / @vmwise -KjB