would this work? I have not tested yet.
$prod_vms = get-content prod_vms.txt
$dmz_vms = get-content dmz_vms.txt
$prod_cluster = get-cluster -server vc "PROD"
$dmz_cluster = get-cluster -server vc "DMZ"
$tasktab1 = @{}
$tasktab2 = @{}
foreach ($vm in $prod_vms) {
write-host "Shutting down prod-vm $vm"
$tasktab1[($vm | stop-vmguest -confirm:$false).id] = $vm
}
foreach ($vm2 in $dmz_vms) {
write-host "shutting down dmz-vm $vm2"
$tasktab2[( $vm2 | stop-vmguest -Confirm:$false).id] = $vm2
#$vm2 | stop-vmguest -confirm:$false
}
$runningtasks1 = $tasktab1.Count
$runningtasks2 = $tasktab2.count
while($runningtasks1 -gt 0){
get-task | % {
if($tasktab1.ContainsKey($_.Id) -and $_.State -eq "Success"){
get-vm $tasktab1[$_.id] | move-vm -Location $prod_cluster -Confirm:$false -RunAsync
get-vm $tasktab1[$_.id] | Start-VM -Confirm:$false -RunAsync
$tasktab1.Remove($_.id)
$runningtasks1--
}
elseif($tasktab1.Contains($_.Id) -and $_.state -eq "Error"){
$tasktab1.Remove($_.id)
$runningtasks1--
}
}
start-sleep -seconds 15
while($runningtasks2 -gt 0){
get-task | % {
if($tasktab2.ContainsKey($_.Id) -and $_.State -eq "Success"){
get-vm $tasktab2[$_.id] | move-vm -Location $prod_cluster -Confirm:$false -RunAsync
get-vm $tasktab2[$_.id] | Start-VM -Confirm:$false -RunAsync
$tasktab2.Remove($_.id)
$runningtasks2--
}
elseif($tasktab2.Contains($_.Id) -and $_.state -eq "Error"){
$tasktab2.Remove($_.id)
$runningtasks2--
}
}
start-sleep -seconds 15