VMware Cloud Community
Merop3004
Contributor
Contributor

Wait untill New-vm is complete

Hi, 

I use this for deploy my VM

How can i wait also for VM deployment finish?
    $task = Get-ContentLibraryItem -ContentLibrary $VMTemplate.ContentLibrary -Name $VMTemplate.name |
    New-VM -Name $Computername -VMHost (Get-Cluster $VCENTER.ClusterName | Get-VMHost | Get-Random) `
    -ResourcePool (Get-Cluster $VCENTER.ClusterName).ResourcePool -Datastore $Datastore `
    -DiskStorageFormat $DiskStorageFormat -RunAsync:$true
    $task
Wait-Task -Task  $task
0 Kudos
1 Reply
LucD
Leadership
Leadership

The best option imho is to wait, in a loop, for the event that marks the end of the creation of the VM.
With the Get-VIEvent cmdlet you can wait for the VMCreatedEvent.


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