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
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
Dear LucD
Great .. the value are ok !
$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"
}
Thanks
Almir