LucD,
I tried test as below to move one small VM to different datastore, but it started to move a bigger size VM randomly,
Please help, whats wrong with the below
$source = "DS03"
$destin = "DS39"
Get-Datastore $source | Get-VM -PipelineVariable vm | Sort-Object -Property ProvisionedSpaceGB | Select -First 1 |
ForEach-Object -Process {
$destDS = Get-Datastore $destin
if ($destDS.FreeSpaceGB / $destDS.CapacityGB -gt 0.15) {
$task = Move-VM -VM $vm -Datastore $destin -RunAsync
while ($task.PercentComplete -ne 100) {
Start-Sleep 5
$task = Get-Task -Id $task.Id
$sProg = @{
Activity = "$vm Storage vMotion from $source to $destin"
Status = "$($task.PercentComplete)%"
PercentComplete = ([int]($task.PercentComplete))
}
Write-Progress @sProg
}
}
else {
Write-Host "Destination doesn't have 20% of free space"
break
}
}