PowerCLI

 View Only
Expand all | Collapse all

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

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

    Posted Jun 27, 2023 12:53 PM

    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?

     



  • 2.  RE: PS script to show VM snapshot sizes differs from what I see in vCenter

    Posted Jun 27, 2023 01:10 PM

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

     



  • 3.  RE: PS script to show VM snapshot sizes differs from what I see in vCenter

    Posted Jun 27, 2023 02:02 PM

    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.

     

     



  • 4.  RE: PS script to show VM snapshot sizes differs from what I see in vCenter

    Posted Jun 27, 2023 06:32 PM

    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.






  • 5.  RE: PS script to show VM snapshot sizes differs from what I see in vCenter

    Posted Jun 28, 2023 08:12 AM

    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

     



  • 6.  RE: PS script to show VM snapshot sizes differs from what I see in vCenter

    Posted Jun 28, 2023 08:24 AM

    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



  • 7.  RE: PS script to show VM snapshot sizes differs from what I see in vCenter

    Posted Jun 28, 2023 08:53 AM

    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.*?



  • 8.  RE: PS script to show VM snapshot sizes differs from what I see in vCenter

    Posted Jun 28, 2023 12:50 PM

    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 



  • 9.  RE: PS script to show VM snapshot sizes differs from what I see in vCenter

    Posted Jun 28, 2023 01:08 PM

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

    Is .NET enabled in the Windows features?



  • 10.  RE: PS script to show VM snapshot sizes differs from what I see in vCenter

    Posted Jun 28, 2023 02:37 PM

    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

     



  • 11.  RE: PS script to show VM snapshot sizes differs from what I see in vCenter

    Posted Jun 28, 2023 02:41 PM

    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



  • 12.  RE: PS script to show VM snapshot sizes differs from what I see in vCenter

    Posted Jun 28, 2023 04:25 PM

    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



  • 13.  RE: PS script to show VM snapshot sizes differs from what I see in vCenter

    Posted Jun 28, 2023 04:34 PM

    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



  • 14.  RE: PS script to show VM snapshot sizes differs from what I see in vCenter

    Posted Jun 29, 2023 02:42 PM

    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?



  • 15.  RE: PS script to show VM snapshot sizes differs from what I see in vCenter

    Posted Jun 29, 2023 02:59 PM

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



  • 16.  RE: PS script to show VM snapshot sizes differs from what I see in vCenter

    Posted Jun 29, 2023 03:38 PM

    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.