VMware Cloud Community
G0nz0UK
Enthusiast
Enthusiast

PS script to show VM snapshot sizes differs from what I see in vCenter

Hello,

I'm using this to how snapshots and their sizes.

Connect-VIServer -Server vc.domain.com -Credential $credentials

get-vm | get-snapshot | select vm, name, description, created, sizegb | Format-Table -Property vm,name,description,created,sizegb

This one shows as having a 2TB snapshot!

G0nz0UK_0-1687870348905.png

 

In vCenter it shows as 80GB

G0nz0UK_1-1687870380327.png

 

As my script wrong?

 

0 Kudos
15 Replies
cristescu28
Contributor
Contributor

See this script : https://powershell.ro/generate-detailed-snapshots-report-using-powercli-scripting/

 

I`m using this part to get the snapshot: 

Get-VM | Sort | Get-Snapshot | Select-Object @{n="VCenter"; e={$VCenter}}, VM, @{n="SnapshotState"; e={$_.PowerState}}, Name, Description, @{Name="SizeGB";Expression={ [math]::Round($_.SizeGB,2) }}, Created, @{Name="DaysOld";Expression={(New-TimeSpan -End (Get-Date) -Start $_.Created).Days }}

 

0 Kudos
wetnose88
Enthusiast
Enthusiast

I noticed the similar issues in our environment, but it is the other way around.

PowerCLI reported the snapshot size less than 1 GB, but in vCenter it is 530GB.

 

 

0 Kudos
LucD
Leadership
Leadership

The Get-Snapshot cmdlet and the Web Client are both showing correct values, the difference is that they are measuring different things.

One is returning the size of the files (mostly the VMDK) before the snapshot (PowerCLI) and the other is returning the size of the delta disks (and some other snapshot-related files) created during/after the snapshot.

Have a look at my yadr – A vdisk reporter post.





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

0 Kudos
G0nz0UK
Enthusiast
Enthusiast

I'm only interested in the snapshot delta size I guess as this is the real size maybe.

I tried your link too and the script there, but it fails on all the labels.  It mentions about >NET 3.5 which is installed and WOW64 which I'm not sure about.  Do you think it's related?

 

PS C:\Windows\system32> C:\Scripts\VMware\Snapshotsplus.ps1

Name                           Port  User                          
----                           ----  ----                          
vc.domain.com    443   VSPHERE.LOCAL\logs     
Add-Type : Cannot add type due to the following exception: Compiler executable file csc.exe cannot be found.. Verify that Microsoft .NET Framework 3.5  is installed. On x64-based versions of Windows, you must 
also install the WOW64 feature.
At C:\Scripts\VMware\Snapshotsplus.ps1:27 char:1
+ Add-Type -Language CsharpVersion3 -TypeDefinition $DiskInfoDef
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Type], InvalidOperationException
    + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.AddTypeCommand
 
New-Object : Cannot find type [DiskInfo]: verify that the assembly containing this type is loaded.
At C:\Scripts\VMware\Snapshotsplus.ps1:63 char:15
+         $diskInfo = New-Object DiskInfo
+                     ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
 
The property 'VMname' cannot be found on this object. Verify that the property exists and can be set.
At C:\Scripts\VMware\Snapshotsplus.ps1:64 char:3
+         $diskInfo.VMname = $vm.Name
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
 
The property 'Label' cannot be found on this object. Verify that the property exists and can be set.
At C:\Scripts\VMware\Snapshotsplus.ps1:65 char:3

 

0 Kudos
G0nz0UK
Enthusiast
Enthusiast

Another example of my script I originally posted at the top is this one below.  In vCenter it is showing it has a 4.06TB snapshot, but my report shows it as 64.8GB.  It's as if it's just looking at the main .vmdk

G0nz0UK_0-1687940559299.png

Is there anyway to change/update my script to show the same as vCenter?

Thanks

0 Kudos
LucD
Leadership
Leadership

The impression that is looking only at the main VMDK is because that is probably the biggest file.
You should see that it not the main VMDK when you have multiple snapshots and you look at the latest snapshot.

Are you running the script with PSv5.1 or PSv7.*?


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

0 Kudos
G0nz0UK
Enthusiast
Enthusiast

I'm using:

PSVersion 5.1.17763.3770

VMware.PowerCLI 12.5.0 build 19195797

So it seems PS sees the biggest file whereas vCenter somehow uses the smaller delta 

0 Kudos
LucD
Leadership
Leadership

No, that is not what I said.
Check with a VM with 2 fresh snapshots.

Is .NET enabled in the Windows features?


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

0 Kudos
wetnose88
Enthusiast
Enthusiast

I tested the yadr – A vdisk reporter, it is working for me, the Snap1MB size still different from vSphere. I need some more research to figure out.

wetnose88_1-1687963016672.png

 

0 Kudos
wetnose88
Enthusiast
Enthusiast

BTW, I am running the yadr – A vdisk reporter with PowerShell 5.1.19041.3031 and PowerCLI 12.7.0 build 20091289

PS C:\docs\scripts> $PSversionTable

Name Value
---- -----
PSVersion 5.1.19041.3031
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.3031
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1


PS C:\docs\scripts> get-powercliversion

PowerCLI Version
----------------
VMware.PowerCLI 12.7.0 build 20091289
---------------
Component Versions
---------------
VMware Common PowerCLI Component 12.7 build 20067789
VMware Cis Core PowerCLI Component PowerCLI Component 12.6 build 19601368
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 12.7 build 20091293

0 Kudos
G0nz0UK
Enthusiast
Enthusiast

Check with my script with a VM and 2 snapshots or the one in your link?

Looks like 3.5 won't install on this WIn2029 server for some reason.

G0nz0UK_0-1687969314443.png

then 

G0nz0UK_1-1687969490746.png

What a pain, I'll look into this part.  I'll try this:

DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:X:\sources\sxs

0 Kudos
LucD
Leadership
Leadership

That is a known issue when trying to install .NET 3.5.
Search for .NET 3.5 and 0x800f0954

You can try one of the methods in How to enable .NET Framework 3.5 on Windows Server 2019, 2022 - GreenCloud Documentation


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

0 Kudos
G0nz0UK
Enthusiast
Enthusiast

Thanks I got that installed and the script runs!

This is what I see for that server:

G0nz0UK_0-1688049598367.png

 

But in venter it's saying 80G

What is right and what is wrong?

0 Kudos
LucD
Leadership
Leadership

Both are correct, they just measure different things (see my earlier reply)


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

0 Kudos
G0nz0UK
Enthusiast
Enthusiast

So based on that screenshot is vCenter just returning the size of the main vmdk before a snapshot, but shows in vCenter as that snapshot size?

G0nz0UK_0-1688053038647.png

 

Apologies I'm not grasping this.

0 Kudos