temp_stuff
Contributor
Contributor

PowerCLI reports wrong snapshot sizes

Hello.

I'm trying to find the the largest VMs administered by a vCenter Server, the largest snapshots in those VMs and associate them with the users that created them.

The part about getting VMs and sorting them by size looks more or less like this:

$VIServer = Connect-VIServer -Server $ServerURL -User $Username -Password $Password

$VMs = Get-Datacenter -Server $VIServer -Name $Datacenter | Get-VMHost -Name $VMHost | Get-VM -Name $VMName

$VMs | Select-Object Name,PowerState,@{l='Size in GB'; e={[math]::Round(($_.UsedSpaceGB),2)}} | Sort-Object -Property "Size in GB" -Descending

This works and gives the expected results.

To find who create the snapshots I used Get-VIEvent to correlate with the event log like here. This too kinda works. (Some events aren't in the log anymore, but that's a stupid known limitation.)

But when I try to sort them by size is when things go terribly wrong.

Lets take the top VM from the VMs I got in the previous step and look at its snapshots:

PS C:\> $VM = $VMs | Sort-Object -Property "UsedSpaceGB" -Descending | Select -First 1

PS C:\> $VM | Format-Table Name,PowerState,@{l='Size in GB'; e={[math]::Round(($_.UsedSpaceGB),2)}}

Name               PowerState Size in GB

----               ---------- ----------

10 -QA- Win 10 x32  PoweredOn     455.45

This is correct:

pastedImage_15.png

Now lets take a look at its snapshots (redacted output, removed quite a few snapshots):

PS C:\> $VM | Get-Snapshot | Measure-Object -Sum -Property SizeGB

Count    : 33

Average  :

Sum      : 747.049196921289

Maximum  :

Minimum  :

Property : SizeGB

PS C:\> $total = 0

PS C:\> foreach ($snap in $VM | Get-Snapshot | Sort-Object -Property SizeGB -Descending)

{

    $snapevent = Get-VIEvent -Entity $snap.VM -Types Info -Finish $snap.Created -MaxSamples 1 | Where-Object {$_.FullFormattedMessage -imatch 'Task: Create virtual machine snapshot'}

    $total = $total + $snap.SizeGB

    $size = [math]::Round(($snap.SizeGB),2)

    if ($snapevent -ne $null) {

        Write-Host ("(" + $size + ") VM: "+ $snap.VM + ". Snapshot '" + $snap + "' created on " + $snap.Created.DateTime + " by " + $snapevent.UserName +".")

    } else {

        Write-Host ("(" + $size + ") VM: "+ $snap.VM + ". Snapshot '" + $snap + "' created on " + $snap.Created.DateTime + ". This event is not in vCenter events database")

    }

}

(98.88) VM: 10 -QA- Win 10 x32. Snapshot 'Winver' created on Sunday, 24 June 2018 18:27:42. This event is not in vCenter events database

(86.28) VM: 10 -QA- Win 10 x32. Snapshot 'Winver 1709.16299.214' created on Thursday, 1 February 2018 11:26:23. This event is not in vCenter events database

(80.30) VM: 10 -QA- Win 10 x32. Snapshot '***Windows Fall Creator - installed!! ***' created on Wednesday, 3 January 2018 16:05:08. This event is not in vCenter events da

tabase

(28.74) VM: 10 -QA- Win 10 x32. Snapshot 'Winver 1803 17134.1' created on Wednesday, 9 May 2018 16:04:12. This event is not in vCenter events database

(20.71) VM: 10 -QA- Win 10 x32. Snapshot 'Winver 1803 - 17134.1' created on Monday, 14 May 2018 11:44:01. This event is not in vCenter events database

(12.67) VM: 10 -QA- Win 10 x32. Snapshot 'winver 1803-17134.112' created on Tuesday, 17 July 2018 17:46:16 by ***.

(8.34) VM: 10 -QA- Win 10 x32. Snapshot 'Winver 16299.248' created on Thursday, 15 February 2018 15:01:56. This event is not in vCenter events database

(4.88) VM: 10 -QA- Win 10 x32. Snapshot 'Machine time tests - Do not delete' created on Sunday, 1 July 2018 14:55:00. This event is not in vCenter events database

(4.01) VM: 10 -QA- Win 10 x32. Snapshot 'Base - do not make new snapshots based on this' created on Thursday, 30 July 2015 10:50:56. This event is not in vCenter events d

atabase

PS C:\> $total

747.04919692128896713256835936

As you can see the manual count and Measure-Object agree about the total size, and it's much bigger than the size of the machine.

The per-snapshot sizes are also wrong. For example:

Base take more than PowerCLI reports (28 > 4):

pastedImage_39.png

but "Winver" doesn't take 98GB:

pastedImage_41.png

"'Winver 1709.16299.214" doesn't take 86GB:

pastedImage_42.png

"***Windows Fall Creator - installed!! ***" doesn't take 80GB:

pastedImage_43.png

etc. (You can use the dates to see that those are the correct snapshots and not other snapshots with similar names.)

What's up with that?

The closest thing I found was this topic, but it suggest that the problem is with vSphere itself, while I see that the vSphere web client reports much more reasonable sizes, so the problem seems to be with PowerCLI itself.

Is there an alternative way to get that information in code, assuming that I can't upgrade to 6.5U2

0 Kudos
1 Reply
LucD
Leadership
Leadership

First, yes I agree, the snapshot sizes reported by Get-Snapshot are not reflecting what I would like to see for the snapshot size.

But also the sizes you see reported in the Web Client do not show the size I would like to see.

In fact, I did a post on this, see Yadr – A Vdisk Reporter

In that script I look at the actual file sizes of the delta files for each snapshot.

Have a look, and a test run.


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

0 Kudos