VMware Cloud Community
yonish
Contributor
Contributor

VMware vCloud Storage vmotion by Datastore and vDC ( Resource Pool )

This Shell will help you migrate the vm's between datastores that are managed by vcloud director (  Resource pool ) from the vi probably you will get an error the are insufficient for the operation and etc. it will make it more quicker and more efficient.

There is a problem to do storage vmotion to a vm that is in a resource pool ( vcloud vdc is using resource pools ) that are using most of the resources of the vdc ( resource pool ) in my environment most of the org's are using 90 % and more of the total resources that are allocated to them.

The shell will get all the vm's in the in current datastore and then will get all the resource pools of the those machines and set them for Mem and cpu to Expandable just for around 15 seconds ( it is very important to make sure the period time for the Expandable is very low and it can adjustable ) to avoid swapping and unnecessary ballooning.

Please notice if you got a lot of vm's in the datastore current $cds and you are not using confirm or you will answer yes you can find your self with lot's of svmotions.

$vmne= "vm name (41330147-837a-455e-a607-453e5cbdeb23)" # vm to exclude for example very large or heavy  io machine
$lt_size="200" #  vm to exclude latger than size in GB
$cds=  "ds_vcloud_xiv #  storage vmotion current datastore
$tds=  "ds_vcloud1_pvdc1_lun1" # storage vmotion to datastore
$vms= Get-Vm -datastore $cds| where {$_.Name -ne $vmne } | Where { $_.UsedSpaceGB -lt $lt_size }
($vms).count
$res=Get-ResourcePool -VM $vms
$res | select name,MemExpandableReservation,CpuExpandableReservation | ft -AutoSize
$res | Set-ResourcePool -CpuExpandableReservation:$true -MemExpandableReservation:$true
$vms | Move-VM -Datastore $tds -RunAsync -confirm:$true # notice if you are not using confirm or in the confirm answering yes you could move lot of vm together
Start-Sleep 10
$res | Set-ResourcePool -CpuExpandableReservation:$false -MemExpandableReservation:$false

0 Kudos
0 Replies