Marco_2_G
Contributor
Contributor

Removing snapshots found with get-view

Jump to solution

Hello!

I have already posted another question here, so if you need some backgroundinfo... Smiley Happy

Anyway, I have gathered a list of vms that need their snapshots removed. I would like to do this with get-view since I seem to be getting a lot of errors of this kind:

Get-VIObjectByVIView : 25.05.2018 09:52:05    Get-VIObjectByVIView        The object has already been deleted or has not been completely created

When I try to convert it to an object.

An example of the command I use is this:

(Get-View -ViewType VirtualMachine -Filter @{"Summary.VM"=".*vm-1925199"}).rootsnapshot | Get-VIObjectByVIView

So the idea was to use a method in get-view directly, however the method RemoveAllSnapshots I have found mentioned on the internet is not available anymore.

So is there still a way to invoke a Delete All Snapshots from get-view?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Sure there is, try like this.

The $true parameter tells the system to consolidate after the removal.

There is no need to have the '.*' in the RegEx expression.

$vm = Get-View -ViewType VirtualMachine -Filter @{'Summary.VM' ='vm-1925199'}

$vm.RemoveAllSnapshots($true)


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership

Sure there is, try like this.

The $true parameter tells the system to consolidate after the removal.

There is no need to have the '.*' in the RegEx expression.

$vm = Get-View -ViewType VirtualMachine -Filter @{'Summary.VM' ='vm-1925199'}

$vm.RemoveAllSnapshots($true)


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

0 Kudos
Marco_2_G
Contributor
Contributor

Well, now I feel silly. I was looking through the methods of individual snapshots but it makes much more sense to have that function on the VM layer.

Sorry for the stupid question and thank you once more for your help!

0 Kudos