Vimal348
Enthusiast
Enthusiast

Remove snapshots using script

Jump to solution

Hello,

I have created snapshots for many VMs with the description:"Prior to install VM Hardware"

Can someone please tell me how to remove those snapshots that has a description : "Prior to install VM Hardware"

$vmlist = Get-Content "C:\VM\Snapshots\vmlists.txt"

foreach($VM in $VMlist) {

    Get-Snapshot -VM $vm |

    Remove-Snapshot -Confirm:$false

}

Disconnect-VIServer -Confirm:$false

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Then you could try like this

$vmlist = Get-Content "C:\VM\Snapshots\vmlists.txt"

foreach($VM in $VMlist) {

    Get-Snapshot -VM $vm | where{$_.Description -eq 'Prior to install VM Hardware'} |

    Remove-Snapshot -Confirm:$false

}

Disconnect-VIServer -Confirm:$false


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership

Try like this

$vmlist = Get-Content "C:\VM\Snapshots\vmlists.txt"

foreach($VM in $VMlist) {

    Get-Snapshot -VM $vm -Name 'Prior to install VM Hardware' |

    Remove-Snapshot -Confirm:$false

}

Disconnect-VIServer -Confirm:$false


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

0 Kudos
Vimal348
Enthusiast
Enthusiast

Hello LucD​,

Thank you for your script. Your suggestion works for the snapshot that has the name: 'Prior to install VM Hardware',

Here my snapshot names are different for each VMs, but Description is same : 'Prior to install VM Hardware',

Hence, is it possible to delete the snapshot collecting that Description name: 'Prior to install VM Hardware',

Upload and share screenshots and images - print screen online | Snipboard.io

0 Kudos
LucD
Leadership
Leadership

Then you could try like this

$vmlist = Get-Content "C:\VM\Snapshots\vmlists.txt"

foreach($VM in $VMlist) {

    Get-Snapshot -VM $vm | where{$_.Description -eq 'Prior to install VM Hardware'} |

    Remove-Snapshot -Confirm:$false

}

Disconnect-VIServer -Confirm:$false


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

View solution in original post

0 Kudos
Vimal348
Enthusiast
Enthusiast

Thank you LucD

The script works perfectly...

0 Kudos