VMware Cloud Community
vwmagic
Enthusiast
Enthusiast

Powercli Commands to list SnapShot size on a Datastore?

I am seeking a PowerCLI command to list SnapShots size with a Datastore on the storage level.  I could not find the information in GUI.

Thank You!

Reply
0 Kudos
10 Replies
a_p_
Leadership
Leadership

Discussion moved from VMware vSphere™ to VMware PowerCLI

Reply
0 Kudos
LucD
Leadership
Leadership

You could do something like this

$dsName = 'datastore1'

$ds = Get-Datastore -Name $dsName

$snaps = $ds | Get-VM | Get-Snapshot

$ds | Select Name,@{N='SnapshotSizeGB';E={

   [math]::Round(($snaps | Measure-Object -Property SizeGB -sum).Sum,1)}}


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

Reply
0 Kudos
vwmagic
Enthusiast
Enthusiast

LucD,

I am looking for Snapshots for Datastore on NFS storage level, not for VM's. 

Thanks for replying.

Reply
0 Kudos
LucD
Leadership
Leadership

Not sure I get what you mean.
Can you show a screenshot? Or some more details?


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

Reply
0 Kudos
vwmagic
Enthusiast
Enthusiast

.snapshot

this is the folder in vSphere.

Commands you showed me is for snapshots accumulated by VM's.

The snapshots I am talking about is taken by the storage, not by VM's or vShpere.

Reply
0 Kudos
LucD
Leadership
Leadership

Ok, got it.

Try something like this

$datastoreName = 'MyDS'

$ds = Get-Datastore -Name $datastoreName

New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root '\' | Out-Null


$size = Get-ChildItem -Path "DS:\.snapshot" -Recurse | Measure-Object -Property Length -Sum | select -ExpandProperty Sum


Remove-PSDrive -Name DS -Confirm:$false


Write-Host "Folder .snapshot holds $([math]::Round($size/1GB,1)) GB"


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

Reply
0 Kudos
vwmagic
Enthusiast
Enthusiast

Your script is hanging on the line with Recursive...

Any idea why?

Thanks!

Reply
0 Kudos
LucD
Leadership
Leadership

The datastore provider is not extremely fast.

I suspect it just might be running for a very long time.

You could test with a datastore that has less content.


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

Reply
0 Kudos
vwmagic
Enthusiast
Enthusiast

After extremely long time, it finally broken.  The Snapshots size is not that large, only 10 ones.

Reply
0 Kudos
LucD
Leadership
Leadership

Do you mean 'completed' or 'ended with an error' with 'broke'?


It's not as much the size of the files in that folder, more the number of files and how deep the folders are nested, that determines how long it will run.

An alternative, and faster method, would be to connect via SSH to the ESXi nodes, and do a 'du' from there.

But it require to enable SSH and have access to an account that can logon on the ESXi node.


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

Reply
0 Kudos