sub _remove_snap { my ( $vm ) = @_; # skip if no snapshots on vm unless ( defined $vm->snapshot ) { print $vm->name . " has no snapshots, skipping\n"; return; } my $snaps = _find_snapname( $vm->snapshot->currentSnapshot, $vm->snapshot->rootSnapshotList ); print Dumper $snaps; } sub _find_snapname { my ( $ref, $tree ) = @_; my $counter = 0; my @snaps; foreach my $node (@$tree) { # print $node->name, "\t" . $node->createTime . "\n"; if ( $node->name eq $snapname ) { push @snaps, $node } _find_snapname( $ref, $node->childSnapshotList ); } print Dumper @snaps; return \@snaps; } #### $VAR1 = bless( { 'createTime' => '2017-12-07T21:10:30.643627Z', 'name' => '2', 'state' => bless( { 'val' => 'poweredOff' }, 'VirtualMachinePowerState' ), 'description' => '', 'id' => '42', 'snapshot' => bless( { 'type' => 'VirtualMachineSnapshot', 'value' => '38-snapshot-42' }, 'ManagedObjectReference' ), 'vm' => bless( { 'value' => '38', 'type' => 'VirtualMachine' }, 'ManagedObjectReference' ), 'childSnapshotList' => [ bless( { 'snapshot' => bless( { 'type' => 'VirtualMachineSnapshot', 'value' => '38-snapshot-43' }, 'ManagedObjectReference' ), 'vm' => bless( { 'value' => '38', 'type' => 'VirtualMachine' }, 'ManagedObjectReference' ), 'replaySupported' => '0', 'quiesced' => '0', 'state' => bless( { 'val' => 'poweredOff' }, 'VirtualMachinePowerState' ), 'name' => '3', 'createTime' => '2017-12-07T21:11:45.892562Z', 'id' => '43', 'description' => '' }, 'VirtualMachineSnapshotTree' ) ], 'quiesced' => '0', 'replaySupported' => '0' }, 'VirtualMachineSnapshotTree' ); $VAR1 = [];