VMware vSphere

 View Only
  • 1.  Snapshot Size

    Posted Aug 17, 2016 04:39 PM

    Hi,

    Not sure if I'm missing something really obvious, but is there a way of viewing the snapshot size in vSphere 6? SizeMB doesn't seem to be in the output of 'Get-VM | Get-Snapshot' anymore.

    I know I can look at the actual file on the datastore, but that seems a bit barbaric :smileyhappy:



  • 2.  RE: Snapshot Size

    Posted Aug 17, 2016 04:48 PM

    cli to vm folder and

    ls -lrth



  • 3.  RE: Snapshot Size
    Best Answer

    Posted Aug 17, 2016 05:24 PM

    Hi, try this:

    ################################

    #

    # PowerCLI script with list of all Snapshots

    # Created by Jiri Luska on 21/07/2016 @EmbedIT

    #

    ################################

    Write-Host "List of Snapshots on vCenters - script by Jiri Luska @EmbedIT"

    Write-Host ""

    Write-Host -NoNewline "Searching for Snapshots"

    $Report = Get-VM | Get-Snapshot | Select @{N="vCenter";E={$($_.Parent.Client.ServerUri).TrimStart("443@")}},VM,Name,Description,@{Label="Size";Expression={"{0:N2} GB" -f ($_.SizeGB)}},Created

    Write-Host " - DONE"

    If (-not $Report)

    {  $Report = New-Object PSObject -Property @{

          vCenter = ""

          VM = "No snapshots found on any VM's"

          Name = ""

          Description = ""

          Size = ""

          Created = ""

       }

    }

    $Report | Select vCenter,VM,Name,Description,Size,Created | Out-GridView

    #export-csv c:\ps\list-snap.csv -NoTypeInformation

    Also if you are interested in delete all snapshots older than 14 days and keep ones which have in name "do not delete", you can use this:

    (remove Whatif :-) to get rid of DEMO MODE)

    ################################

    #

    # PowerCLI script with action to remove all 14 days old snapshots except ones with mark "do not delete"

    # Created by Jiri Luska on 21/07/2016 @EmbedIT

    #

    ################################

    Write-Host "Remove 14 days old Snapshots from vCenters - script by Jiri Luska @EmbedIT"

    Write-Host ""

    Write-Host -NoNewline "Searching for Snapshots"

    $SometimeAgo = (Get-Date).AddDays(-14)

    $Snap = Get-VM | Get-Snapshot

    Write-Host " - DONE"

    Write-Host ""

    Write-Host "Performing remove: DEMO MODE"

    ForEach($VMHost in $Snap)

    {

        if ($VMHost.Created -lt $SometimeAgo) {

            if ($VMHost.Name -like "*do not delete*") {

                Write-Host "Shipping marked snapshot: " $VMHost.VM.Name " - " $VMHost.Name

            } else {

                Write-Host "Removing snapshot: " $VMHost.VM.Name " - " $VMHost.Name

                Remove-Snapshot $VMHost -Confirm:$false -WhatIf

            }

        }

    }



  • 4.  RE: Snapshot Size

    Posted Aug 18, 2016 10:25 AM

    Thanks for this, it seems to be working. Can you just explain the following lines in your script please?

    @{N="vCenter";E={$($_.Parent.Client.ServerUri).TrimStart("443@")}}

    @{Label="Size";Expression={"{0:N2} GB" -f ($_.SizeGB)}}



  • 5.  RE: Snapshot Size

    Posted Aug 18, 2016 10:39 AM

    @{N="vCenter";E={$($_.Parent.Client.ServerUri).TrimStart("443@")}}  - Adds a vCenter, which the VM belongs to. I use this script on multiple vCenters connected.


    @{Label="Size";Expression={"{0:N2} GB" -f ($_.SizeGB)}} - Formats expression of output - In GB with 2 decimals.


    BR


    Jiri