VMware Cloud Community
Guv
Enthusiast
Enthusiast

VM snapshots in a datastore

Is there a script I can run to check if VM's on a specific datastore has any snapshots.  We had a datastores in a cluster which ran out of space and want to check if any of VM snapshots may have caused the space decrease.

Any advise on a script which shows a VM on a specfic datatsore has any snapshots and the size as well if any.

Thanks

Reply
0 Kudos
2 Replies
RvdNieuwendijk
Leadership
Leadership

You can get all the snapshots on a specific datastore called MyDatastore with:

Get-Datastore -Name MyDatastore |
Get-VM |
Get-Snapshot |
Select-Object -Property VM,Name,SizeGB

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
LucD
Leadership
Leadership

Since the snapshot files of a VM do not necessarily need to be on the same datastore as the VM homefolder, you could just look at all snapshots and extract those that are on the specific datastore.

Something like this

$dsName = "MyDS"

foreach($vm in Get-VM){   $keys = $vm.ExtensionData.LayoutEx.Snapshot | %{$_.Disk | %{$_.Chain | %{$_.FileKey}}}   $vm.ExtensionData.LayoutEx.File | where {$keys -contains $_.Key -and $_.Name -match $dsName} |
 
Select @{N="VM";E={$vm.Name}},Name
}


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

Reply
0 Kudos