$VMsToMove = Get-DatastoreCluster *linux*V5K* | Get-VM | where-object Name -like "itddhs*" | sort-object UsedSpaceGB ForEach($VM in $VMsToMove){ Write-Warning ($VM.Name + ' ... ' + [math]::round($VM.UsedSpaceGB,2)) $wait = $true while ($wait -eq $true) { $tasks = Get-Task | where-object {$_.Name -like "ApplyStorageDrs*" -and $_.State -eq "Running"} If(@($Tasks).count -lt 1){$wait = $false} Else{$wait=$true; Write-Warning ("[$VM]:Start sleep " + (Get-Date) + " DRS Count: " + @($Tasks).count); start-sleep -Seconds 20} } $Source = $VM | Get-DatastoreCluster $Destination = Get-DatastoreCluster -Name ($Source.Name.split('_')[0] + "_A9K_General") Move-VM -VM $VM -Datastore $Destination -RunAsync Start-Sleep -Seconds 10 }