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
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
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