function Start-VM.Wait { begin { $timeout = 5 * 60 * 1000 Initialize-XenServer:Aliases Start } process { if ($_.is_a_template -or $_.is_control_domain) { return } if ($_.allowed_operations -notcontains "start") { Write-Warning("{0} cannot be started" -f $_.name_label) return } Write-Verbose("Starting {0}..." -f $_.name_label) Start-VM $_ for ($count = 0; $count -le $timeout / 500; $count += 1) { $metrics = Get-VM.GuestMetrics $_ if ($metrics -ne $null -and $metrics.networks.Count -gt 0) { Write-Verbose("VM {0} started" -f $_.name_label) return } Start-Sleep -m 500 } Write-Warning("Timeout starting {0}" -f $_.name_label) } }