See if this helps:
$doathing = $false # <Set this to $true to do a thing! set to $false to see what it would do! $vmGroups = @{'Group01'='dc0' 'Group02'='file0' 'Group03'='fs0' 'Group04'='web'} $i = 1 do { #decipher what things we are doing things to! $groupNumber = "{0:D2}" -f [int]$i $groupName = "Group" + $groupNumber $groupVms = Get-VM | where {$_.Name -match $vmGroups.$groupName -and $_.powerstate -eq 'PoweredOff'} #start the Vms! foreach ($Vm in $groupVms) { Write-Host "Starting $($Vm.Name)" if ($doathing -eq $true){$Vm | Start-VM}else{Write-Host "Didn't start VM $($Vm.Name) because doathing is false!"} } #wait for tools on each Vm! foreach ($Vm in $groupVms) { Write-Host "Waiting for tools on $($Vm.Name)" if ($doathing -eq $true){$Vm | Wait-Tools}else{Write-Host "Didn't wait for tools on VM $($Vm.Name) because doathing is false!"} } $i++ } while($i -le $vmGroups.Count)