I’m using the hash table example that LucD provides in http://www.lucd.info/2010/02/21/about-async-tasks-the-get-task-cmdlet-and-a-hash-table/ with the Move-VM commandlet, but I receive the following errors:
Index operation failed; the array index evaluated to null.
At C:\vmware\test_powershell.ps1:8 char:11
+ $taskTab[ <<<< (Move-VM -VM (Get-VM $Name) -Destination (Get-VMHost $esxN
ame) -RunAsync).Id] = $Name
+ CategoryInfo : InvalidOperation: (System.Collections.Hashtable:
Hashtable) [], RuntimeException
+ FullyQualifiedErrorId : NullArrayIndex
Index operation failed; the array index evaluated to null.
At C:\vmware\test_powershell.ps1:8 char:11
+ $taskTab[ <<<< (Move-VM -VM (Get-VM $Name) -Destination (Get-VMHost $esxN
ame) -RunAsync).Id] = $Name
+ CategoryInfo : InvalidOperation: (System.Collections.Hashtable:
Hashtable) [], RuntimeException
+ FullyQualifiedErrorId : NullArrayIndex
The SVMotion executes, but the script fails after that. My script follows:
$esxName = " esx1.test.local"
$Datastore = "volume1"
$moveVmList = "testVM1","testVM2"
$taskTab = @{}
# Storage vMotion all the VMs specified in $moveVmList
foreach($Name in $moveVmList){
$taskTab[(Move-VM -VM (Get-VM $Name) -Datastore (Get-Datastore $Datastore) -RunAsync).Id] = $Name
}
# vMotion each VM after Storage vMotion is completed
$runningTasks = $taskTab.Count
while($runningTasks -gt 0){
Get-Task | % {
if($taskTab.ContainsKey($_.Id) -and $_.State -eq "Success"){
Get-VM $taskTab[$_.Id] | Move-VM -Destination (Get-VMHost $esxName)
$taskTab.Remove($_.Id)
$runningTasks--
}
elseif($taskTab.ContainsKey($_.Id) -and $_.State -eq "Error"){
$taskTab.Remove($_.Id)
$runningTasks--
}
}
Start-Sleep -Seconds 15
}
I’ve tried different variations to the script using other commandlets, but only appears to fail with the Move-VM commandlet.
Any help would be appreciated.
Thanks!