I had another look at your script, and there is a brace too much after the if-statement.
The elseif part was not inside the foreach block.
Change the code to
$runningTasks = $taskTab.Count
while ($runningTasks -gt 0) {
Get-Task | % {
if ($taskTab.ContainsKey($_.Id) -and $_.State -eq "Success") {
Get-VM $taskTab[$_.Id]
Write-Host Snapshot of $taskTab[$_.Id] is being taken before configuration change. The script will confirm all VM snapshots are complete before proceeding to the next task... -foregroundcolor green
$tasktab[(New-Snapshot -VM $taskTab[$_.Id] -Name BeforeVideoRamChange -RunAsync).Id] = $vm
$taskTab.Remove($_.Id)
$runningTasks--
} # Removed extra brace <===
elseif ($taskTab.ContainsKey($_.Id) -and $_.State -eq "Error") {
$taskTab.Remove($_.Id)
$runningTasks--
}
}
Start-Sleep -Seconds 15
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference