PowerCLI

  • 1.  Snapshot report that includes cluster where VM snapshot is located

    Posted 3 days ago

    Hi All,

    I'm trying to get a scheduled daily report to list any snapshots that are out there, but one of the things I'm trying to include is the cluster/host where the VM is located that has the snapshot.

    Using the following command line, it gives me what I want except the cluster name.

    $snapshot = Get-VM | Get-Snapshot | select VM, Name, Description, Created, SizeMB, SizeGB, @{Name="Cluster"; Expression={ $_.VM.ExtensionData.Parent.Name }} | Sort-Object -Property Name

    output shows something like the following:

    VM                     :  VM Test
    Name                :  VM Test Snapshot 03/11/2025  1:30:24 PM
    Description       :
    Created             :  3/11/2025 1:30:24 PM 
    SizeMB              :  4.89234789234734
    SizeGB               :  0.0047776834886204
    Cluster               :

    There's no description, so that being blank is expected, but the cluster is coming up with no information even though the system is in a test cluster.  I know that cluster isn't a normal properly for get-snapshot, but thought it might pull through from using the get-vm where the property does exist.

    Anyone have any idea how to be able to get the cluster to also show with the other snapshot information above?



  • 2.  RE: Snapshot report that includes cluster where VM snapshot is located

    Posted 3 days ago

    Modifying yours just a little will work.

    Get-VM | Get-Snapshot | select VM, Name, Description, Created, SizeMB, SizeGB, @{Name="Cluster"; Expression={ $_.VM.VMHost.Parent }}

    Or using a pipeline variable will work.

    Get-Cluster -PipelineVariable cluster |
    Get-VM | Get-Snapshot | select @{N='VM';E={$_.VM.Name}}, Name, Description, Created, SizeMB,SizeGB,@{N='Cluster';E={$cluster.Name}}




  • 3.  RE: Snapshot report that includes cluster where VM snapshot is located

    Posted 3 days ago

    Thanks, this is now producing the cluster name so the information is fully there.




  • 4.  RE: Snapshot report that includes cluster where VM snapshot is located

    Posted 3 days ago

    Hi,

    I was just trying this on the command line and it gives me what you are looking for

    ($_.VM | Get-Cluster).Name 

    I revised your code to include it.

    $snapshot = Get-VM | Get-Snapshot | select VM, Name, Description, Created, SizeMB, SizeGB, @{Name="Cluster"; Expression={ ($_.VM | Get-Cluster).Name }} | Sort-Object -Property Name




  • 5.  RE: Snapshot report that includes cluster where VM snapshot is located

    Posted 2 days ago
    Edited by ITSavant 2 days ago

    This is how to do it really fast

    Get-View -ViewType VirtualMachine -Server $vCenter -Property Name, Snapshot | ?{$_.Snapshot} | Sort Name | Get-VIObjectByVIView | Get-Snapshot | Select VM, Name, Description, Created, SizeMB, SizeGB, @{Name="Cluster"; Expression={ ($_.VM | Get-Cluster).Name }}