I need to create a job to move VMs to a different datastore.
I created a script like the following one:
Add-PSSnapin VMware.VimAutomation.Core
Connect-VIServer x.y.z.t -User username
$target = "Datastore2"
$listaVM =
"VM1",
"VM2",
"VM3",
"VM4",
"VM5",
"VM6"
foreach ($vm in $listaVM) {
$vm
Get-VM -Name $vm | Move-VM -Datastore $target -DiskStorageFormat 'Thin'
}
The job looks to work but I need to improve it so that:
- After issuing the command to process VM1 it waits till the move is complete
- If VM2 cannot be moved for any reason the process goes on to process VM3
- After processing each VM I get information about the state of the move (success, error, ...)
Can anybody please help?
Regards
marius