VMware Cloud Community
bvi1006
Enthusiast
Enthusiast
Jump to solution

How to wait for the vm customization to complete

Hi, I am trying to find a way to wait for a vm customization to finish before moving on to the next script. This is for 1 vm only. I did see a script written by Lan Renouf I think, but I do not know how to modify the script to look at the status of just 1 vm instead of multiple. Any help would be appreciated! Here is the link for Alan's if anyone is interested:

http://blogs.vmware.com/vipowershell/2012/08/waiting-for-os-customization-to-complete.html'

Thanks in advance

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Remove the RunAsync parameter


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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

That script is a function that you can call for 1 or more VMs.

.\WaitVmCustomization.ps1 -vmList $vms -timeoutSeconds 600

Just store the 1 VM in the $vms variable.


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

0 Kudos
bvi1006
Enthusiast
Enthusiast
Jump to solution

$vms = 1..2 | % { New-VM -Name  "WinXP-$_" -ResourcePool $vmhost -Template $template -Datastore  $datastore -OSCustomizationSpec $spec }

Ok, so I would just change the 1..2 to 1 only?:

$vms = 1 | % { New-VM -Name  "WinXP-$_" -ResourcePool $vmhost -Template $template -Datastore  $datastore -OSCustomizationSpec $spec }

What does the piping to % mean?

Thanks Luc

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That's an alias for the ForEach statement.

In fact you passing the numbers 1 and 2 to the code block of the ForEach loop.

Since you only want to do 1 VM there is no need to use the ForEach loop.

You can do

$vms = @(New-VM -Name  "WinXP-$_" -ResourcePool $vmhost  -Template $template -Datastore  $datastore -OSCustomizationSpec $spec)

The @() construct is to make sure that the $vms variable will be an array, albeit with only 1 element.


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

0 Kudos
bvi1006
Enthusiast
Enthusiast
Jump to solution

I am using:

$vms = @(New-VM -Name $VMName -VMHost $VMHost -Template $Template -Datastore $Datastore -OSCustomizationSpec $Spec -Confirm:$false -RunAsync)

and the value of $vms becomes "Clone_VM_Task" ... what am I missing?

Thanks Luc

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Remove the RunAsync parameter


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

0 Kudos
bvi1006
Enthusiast
Enthusiast
Jump to solution

Thanks, that was it. 

0 Kudos