VMware Cloud Community
oscarjrodriguez
Contributor
Contributor

Requesting - Comparing Data-stores size to virtual machine size

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 C:\Users\r105884\Desktop\scripts\test.txt
foreach ($vm in $vmlist) {
Move-VM -VM $vm -Datastore 'W200_VPLEX_Managed-Services_VM_003' 

$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.

 

 
0 Kudos
2 Replies
a_p_
Leadership
Leadership

0 Kudos
LucD
Leadership
Leadership

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

Get-VM |

Select Name,UsedSpaceGB,ProvisionedSpaceGB


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos