VMware Cloud Community
Najtsob
Enthusiast
Enthusiast
Jump to solution

Is there a simple way to get all snapshot paths ?

I have tree of snapshot like this

snap1
     |

     ----------|----------|
             snap2   snap3
                                 |--------------|
                            snap4         snap5  

How can I get all paths to the leafs ot this tree ?

Like:

/snap1/snap2
/snap1/snap3/snap4
/snap1/snap3/snap5

Thank you very much.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

This is a quick-and-dirty script that should give you the snapshot paths

function Get-SnapList{
    param($snap,$path)

    $path += "/" + $snap.Name 
    if($snap.ChildSnapshotList){
        $snap.ChildSnapshotList | %{
            Get-SnapList $_ $path        }
    }
    $path
} $vmName = "MyVM"
$vm
= Get-View -ViewType VirtualMachine -Filter @{"Name"=$vmName} if($vm.Snapshot){     $report = $vm.Snapshot.RootSnapshotList | %{         Get-SnapList $_ ""    } } $report


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Perhaps not exactly what you are looking for but my UML diagram your VM, vdisks and snapshots post maps the snapshots graphically in an UML: diagram.

Seriously, you can use the RootSnapshotList and a recursive function to list the tree structure.

That code is available in the UML post.

Let me know if you want a text output only version ?


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

0 Kudos
Najtsob
Enthusiast
Enthusiast
Jump to solution

I need text only version, but I think I would found something in your example.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

This is a quick-and-dirty script that should give you the snapshot paths

function Get-SnapList{
    param($snap,$path)

    $path += "/" + $snap.Name 
    if($snap.ChildSnapshotList){
        $snap.ChildSnapshotList | %{
            Get-SnapList $_ $path        }
    }
    $path
} $vmName = "MyVM"
$vm
= Get-View -ViewType VirtualMachine -Filter @{"Name"=$vmName} if($vm.Snapshot){     $report = $vm.Snapshot.RootSnapshotList | %{         Get-SnapList $_ ""    } } $report


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

0 Kudos
Najtsob
Enthusiast
Enthusiast
Jump to solution

Thank you very much.

0 Kudos