I am attempting to write a small script that will compare the size of one data store and a virtual machines size. I am migrating several virtual machines, and I would like the script to check the size of a datastore if the virtual machine is larger than the datastore's current free space, then it would try another one.I currently have the following:
$vmlist = Get-Content <list of virtual machines>
foreach ($vm in $vmlist) {
Move-VM -VM $vm -Datastore 'A'
}
Draft idea:
for command:{
If
virtual machine < "A" data store current free space
then place virtual machine here
elseif
virtual machine size < "B" data store current free space
ect....
}
Thank you for any help.
Discussion moved from vSphere Command-Line Interface to VMware PowerCLI
When you do a Get-VM the returned object contains 2 properties that might help.
The used space and the provisioned space (important if you want to control overprovisioning).
You can use either to compare to the free space on the datastore, to decide whether to move the VM or nor.
This shows you the 2 properties I mean
Select Name,UsedSpaceGB,ProvisionedSpaceGB
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference