VMware Cloud Community
paullee92
Enthusiast
Enthusiast
Jump to solution

get-snapshot Disk Usage

Hi Team,

I am Running below command to get know snapshot disk usage

Get-VM -Name | Get-Snapshot | Select-Object Vm, created, SizeMB 

The result i am getting different from GUI manage snapshot quite different

One of the VM got 3 snapshot,

1st snapshot disk usage was 600 GB

Second one is 70 GB

Third one is 50 GB

On the powercli result, out put for second and third is correct but for 1st snapshot disk usage, it just showing few mb

The 1st snapshot also showing as children snapshot.

How may i generate an output similar as shown in GUI manage snapshot disk usage

 

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You have to replace that with the name of the VM for which you want to see the snapshots


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

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

function Get-SnapshotInfo
{
    param(
        [VMware.Vim.VirtualMachineSnapshotTree]$Tree
    )

    $snapInfo = Get-View -Id $Tree.Snapshot
    $vm = Get-View -Id $Tree.VM

    $entry = $vm.LayoutEx.Snapshot | where{$_.Key -eq $Tree.Snapshot}
    $files = $vm.LayoutEx.File | where{($entry.Disk | %{$_.Chain[-1]}).FileKey -contains $_.Key}

    New-Object -TypeName PSObject -Property @{
        Name = $Tree.Name 
        Created = $Tree.CreateTime
        SizeGB = [math]::Round(($files | Measure-Object -Property Size -Sum).Sum/1GB,2)
    }
    if($Tree.ChildSnapshotList){
        $Tree.ChildSnapshotList | ForEach-Object -Process {
            Get-SnapshotInfo -Tree $_
        }
    }
}

$vm = Get-VM -Name <vmname>

$vm.ExtensionData.Snapshot.RootSnapshotList |
ForEach-Object -Process {
    Get-SnapshotInfo -Tree $_
}


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

Reply
0 Kudos
paullee92
Enthusiast
Enthusiast
Jump to solution

Hi, 

I getting below error when running the script:

Please advise how to fix this.

At line:25 char:20
+ $vm = Get-VM -Name <vmname>
+ ~
The '<' operator is reserved for future use.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : RedirectionNotSupported

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You have to replace that with the name of the VM for which you want to see the snapshots


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

Reply
0 Kudos