PowerCLI

 View Only
  • 1.  get-snapshot Disk Usage

    Posted May 06, 2021 11:44 AM

    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

     



  • 2.  RE: get-snapshot Disk Usage

    Posted May 06, 2021 07:09 PM

    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 $_
    }


  • 3.  RE: get-snapshot Disk Usage

    Posted May 07, 2021 02:14 AM

    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

     



  • 4.  RE: get-snapshot Disk Usage
    Best Answer

    Posted May 07, 2021 06:02 AM

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