VMware Cloud Community
MicroMarket
Contributor
Contributor

how im can check free space in datastore before use new-vm for cloning ?

Dear Friend

how im can check free space in datastore before use new-vm for cloning ?


$esx = Get-VMHost -Name server1.riodejaneiro.caixa

$mydatastore = Get-Datastore -VMHost $esx -Name METALUN_01

Result of variable  mydatastore

Name                           FreeSpaceGB  CapacityGB
----                           -----------  ----------
METALUN_01                    23,098   1.023,750

The comand to clone is :

New-vm -Name $newvmname -VM $fromVMname -Datastore ($mydatastore) -VMHost $esx

Thanks

Almir

0 Kudos
2 Replies
LucD
Leadership
Leadership

You can get the committed storage used by the source VM, like this

$vm = Get-VM -Name $fromVMName

$vmStorageUsedGB = ($vm.ExtensionData.Storage.PerDatastoreUsage | Measure-Object -Property Committed -Sum | select -ExpandProperty Sum)/1GB

Then compare this against FreeSpaceGB from the Get-Datastore


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

0 Kudos
MicroMarket
Contributor
Contributor

Dear LucD

Great .. the value are ok !  Smiley Happy


$vmStorageUsedGB = ($vm.ExtensionData.Storage.PerDatastoreUsage | Measure-Object -Property Committed -Sum | select -ExpandProperty Sum)/1GB

$vmStorageUsedGB

11,0003310870379


$mydatastore = Get-Datastore -VMHost $esx -Name ST310_METALUN_04

$mydatastore2 = $mydatastore.FreeSpaceGB

$mydatastore2

23,09765625

        #

       if ($mydatastore2 -gt $vmStorageUsedGB) {

        Write-Host "dont have space"

        }

      else{

      Write-Host "dont have space"

      }

Have space

Thanks

Almir

0 Kudos