Automation

 View Only
  • 1.  Delete All Snapshots for a VM

    Posted May 05, 2015 09:38 AM

    Hi All,

    Snapshots are getting deleted one by one when I am executing below Command.

    I need to delete all snapshots for specific VMs on a specific Period of time so I would like to schedule the same.

    Get-VM VM1 | Remove-Snapshot

    Is there any way to delete all Snapshot at a time as we have option in vSphere Client.



  • 2.  RE: Delete All Snapshots for a VM

    Posted May 05, 2015 09:41 AM

    Select the 1st snapshot in the tree and then add the RemoveChildren switch.



  • 3.  RE: Delete All Snapshots for a VM

    Posted May 05, 2015 10:09 AM

    Alternatively you can try using the below cmdlet which also can delete all snapshots of a VM.

    Get-VM VM | Get-Snapshot | Remove-Snapshot -Confirm:$false



  • 4.  RE: Delete All Snapshots for a VM

    Posted May 05, 2015 10:31 AM

    Hi Prakash,

    I have tried your command but still snapshot is getting deleted one by one.

    Thanks



  • 5.  RE: Delete All Snapshots for a VM

    Posted May 05, 2015 10:31 AM

    Hi Lucd,

    Snapshot name will be unique for each VM, Is there any way to select 1st snapshot.

    I have tried below that that doesn't work.

    Get-VM VM1 | Remove-snapshot -snapshot * -RemoveChildren -confirm:$false

    But getting error that * system.string conversion is not possible.



  • 6.  RE: Delete All Snapshots for a VM
    Best Answer

    Posted May 05, 2015 10:35 AM

    Sort the snapshots on the Created property, the take the oldest one.

    Something like this

    Get-VM -Name MyVM | Get-Snapshot | Sort-Object -Property Created | Select -First 1



  • 7.  RE: Delete All Snapshots for a VM

    Posted May 05, 2015 10:45 AM

    That works fine. Below is the full command which I have used.

    Get-VM -Name VM1| Get-Snapshot | Sort-Object -Property Created | Select -First 1 | Remove-Snapshot -RemoveChildren -Confirm:$false

    Thank you so much Lucd.