VMware Cloud Community
BenConrad
Expert
Expert
Jump to solution

Multiple datastores are hidden when a snapshot exists

Hi Folks,

I've noticed that if I have a multi-datastore VM the list of datastores = 1 when a snapshot exists:

C:\> get-vm -Name xxxxx | get-datastore

Name FreeSpaceMB CapacityMB

-


-


-


TST-XXXXXXX-VOL1 5095 61184

TST-XXXXXXX-VOL2 21986 61184

... Create a snap and rerun....

C:\> get-vm -Name xxxxx | get-datastore

Name FreeSpaceMB CapacityMB

-


-


-


TST-XXXXXXX-VOL1 21986 61184

I'm writing a snapshot report and one of the things I wanted to retrieve is the total size (MB) of the snapshots. I'm currently using SearchDatastoreSubFolders_Task to get the list of DELTA files.

If I rely on get-datastore the list of datastores = 1. Same result when viewing via the VI client. I can see that the .vmx of the VM has the info I need but I don't want to use a Putty solution to get that data. Any thoughts on how I can list all datastore names when a snapshot exists?

Ben

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

What you are seeing is in fact "working as designed".

Each VM has a property called SnapshotDirectory, which by default is the VM's "home directory".

The result is that after a snapshot the "new" disk file that records the changes since the snapshot is located in the VM's home directory.

To calculate the size of all the files the VM is using you will first have to find out on which other datastores/directory there are files present.

This can be done via the Layout.Disk.DiskFile property.

The following script shows how to access this property.

$vm = get-vm <VM-name> | Get-View
Write-Host $vm.Name "- Snapshot directory:" $vm.Config.Files.SnapshotDirectory

foreach($disk in $vm.Layout.Disk){
  foreach($dev in $vm.Config.Hardware.Device){
    if($dev.key -eq $disk.Key){
	  Write-Host $dev.DeviceInfo.Label
	  break
	}
  }
  foreach($file in $disk.DiskFile){
    Write-Host "`t" $file
  }
}


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

What you are seeing is in fact "working as designed".

Each VM has a property called SnapshotDirectory, which by default is the VM's "home directory".

The result is that after a snapshot the "new" disk file that records the changes since the snapshot is located in the VM's home directory.

To calculate the size of all the files the VM is using you will first have to find out on which other datastores/directory there are files present.

This can be done via the Layout.Disk.DiskFile property.

The following script shows how to access this property.

$vm = get-vm <VM-name> | Get-View
Write-Host $vm.Name "- Snapshot directory:" $vm.Config.Files.SnapshotDirectory

foreach($disk in $vm.Layout.Disk){
  foreach($dev in $vm.Config.Hardware.Device){
    if($dev.key -eq $disk.Key){
	  Write-Host $dev.DeviceInfo.Label
	  break
	}
  }
  foreach($file in $disk.DiskFile){
    Write-Host "`t" $file
  }
}


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

0 Kudos
BenConrad
Expert
Expert
Jump to solution

Fancy! Thanks.

I totally overlooked the VirtualMachineFileLayout object.

Ben

0 Kudos