Any way I look at disks, the filename shows the .vmdk.
$vm.ExtensionData.Layout.Disk
$vm | Get-Harddisk | Select-Object Filename
($vm | Get-Harddisk).ExtensionData.Backing.Filename
These all return "[datastore01] testvm/testvm.vmdk".
But, looking at $vm.ExtensionData.LayoutEx.File, I see 2 files:
Name : [datastore01] testvm/testvm.vmdk
Type : diskDescriptor
Name : [datastore01] testvm/testvm-flat.vmdk
Type : diskExtent
What connects the diskExtent to the Harddisk?
The extent is mentioned in the header of the Descriptor VMDK file
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, Luc,
And how do I get that from PowerCLI?
PSdrive doesn't let me Get-Content.
Indeed, that PSProvider is quite limited.
I normally do something like this.
These header files are normally quite small in size, so it shouldn't take long
$vmName = 'MyVM'
$hdName = 'Hard disk 1'
$vm = Get-VM -Name $vmName
$hd = Get-HardDisk -Name $hdName -VM $vm
$ds = Get-Datastore -RelatedObject $hd
$path = $ds.DatastoreBrowserPath, $hd.Filename.Split(' ')[1].Replace('/','\') -join '\'
$file = [System.IO.Path]::GetTempFileName()
Copy-DatastoreItem -Item $path -Destination $file
$line = Get-Content -Path $file | where{$_ -match '-flat.vmdk'}
$line.Split(' ')[3].Trim('"')
Remove-Item -Path $file
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Didn't know about Copy-DatastoreItem. Thanks, that's cool.
Of course, I immediately ran into a non-small file case and would have to download many GB. That's not going to work for me.
I'm surprised that the contents of the disk descriptor are not part of the disk object.
These header files might show that they are several GB in size, but is not the actual size afaik.
The bulk of the size sits in the flat part.
Did you actually try the download?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I did. There are no -flat files in this case so it is downloading 28G:
Name : [datastore01] 14c68a60-25f3-af76-b3f5-0025b50ac048/vmtest-4.vmdk
Type : diskDescriptor
Size : 28307357696
UniqueSize : 28307357696
Name : [datastore01] 14c68a60-25f3-af76-b3f5-0025b50ac048/vmtest-4-000001.vmdk
Type : diskDescriptor
Size : 343932928
UniqueSize : 343932928
No -flat files?
What type of VMDK is that? And on which type of datastore?
I tested and used my code only on VMFS datastores
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I halted the copy and took a look at the top of the file:
# Extent description
RDONLY 50331648 SPARSE "generated-stream.vmdk"
This is on VSAN and has a snapshot.
Yes, VMDK on VSAN are organised slightly different.
I will have to check if I can adapt the code to work with VSAN datastores.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference