Thank you. Found some code to tweak almost the same moment you posted your answer. I think this is based on something you had posted a few months back actually. So, kudos to you.
The only problem I am having right now is that I cannot get this to play nicely with "-RunAsync". I am on vCenter 4.1, ESX 4.1 U2, PowerCli 5.
$vms = Import-Csv "C:\scripts\vms.csv"
$cloneTask = foreach ($customer in $vms) { Get-HardDisk -vm $customer.name | Where {$_.Name -eq "Hard disk 1"} | % {Set-HardDisk -HardDisk $_ -Datastore $customer.lun -Confirm:$false } }
$ConfigTask = foreach ($vm in $vms){
$vmName = Get-VM -Name $vm.name
$tgtConfigDS = Get-Datastore -Name $vm.lun
$vm = Get-VM -Name $vm.name
$hds = Get-HardDisk -VM $vm
$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
$spec.datastore = (Get-Datastore -Name $tgtConfigDS).Extensiondata.MoRef
$hds | %{
$disk = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator
$disk.diskId = $_.Extensiondata.Key
$disk.datastore = $_.Extensiondata.Backing.Datastore
$spec.disk += $disk
}
$vm.Extensiondata.RelocateVM_Task($spec, "defaultPriority")
}
I have been trying to add it near the -Confirm:$false but that is not working. Any ideas of where I am off track?
Thank you.