Reply to Message

View discussion in a popup

Replying to:
LucD
Leadership
Leadership

Yes, if a number of conditions are met:

  • VM needs to be powered off
  • VM may not have snapshots
  • The harddisk must Thin
  • There should be sufficient free space on the datastore where the VMDK is located

In that case, you can use the InflateVirtualDisk method.

$vmName = 'MyVM'

$datastoreName = 'Datastore_005'


$vm = Get-VM -Name $vmName

if($vm.PowerState -ne 'PoweredOff'){

    Write-Host "The VM needs to be powered off"

}

if(Get-SNapshot -VM $vm){

    Write-Host "There may not be snapshots on the VM"   

}


$si = Get-View ServiceInstance

$vmdkMgr =  Get-View -Id $si.Content.VirtualDiskManager

$dc = Get-Datacenter -VM $vm


Get-HardDisk -VM $vm | where{$_.StorageFormat -eq 'Thin' -and $_.Filename -match $datastoreName} |

ForEach-Object -Process {

    Write-Host "Inflating $($_.Name) on $($vm.Name)"

    $vmdkMgr.InflateVirtualDisk($_.Filename,$dc.ExtensionData.MoRef)

}


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

Reply
0 Kudos