Simple Way to Delete all Snapshots on vSphere - PowerCLI


Have our virtualization environment free of snapshots is a best practice to prevent low storage problems and performance degradation.

  1. Check you environment for snapshots older than 7 day's, using the command:

    Get-VM| Get-Snapshot |Where {$_.Created -lt (Get-Date).AddDays(-7)}| Select-Object VM,Name,Created,@{N="SizeGB";E={[math]::round($_.SizeGB, 1)}} | FT
    

  2. Delete all snapshots for a specific VM run:

    Get-VM MYVM-NAME| Get-Snapshot | Remove-Snapshot -RemoveChildren -Confirm:$False
    

  3. If you want delete all snapshots for all VM's use:

    Get-VM | Get-Snapshot | Remove-Snapshot -RemoveChildren -Confirm:$False
    

  4.  Sometimes delete snapshots fail in consolidation process and snapshot manager don't show snapshots. To check if all VM's are OK run:

    Get-VM | Where-Object {$_.Extensiondata.Runtime.ConsolidationNeeded}
    

  5.  To start consolitation process execute:

    Get-VM | Where-Object {$_.Extensiondata.Runtime.ConsolidationNeeded} | foreach {$_.ExtensionData.ConsolidateVMDisks_Task()}
    
Reference:

https://www.vmware.com/support/developer/PowerCLI/PowerCLI65R1/html/Get-VM.html
https://www.vmware.com/support/developer/PowerCLI/PowerCLI65R1/html/Get-Snapshot.html
https://www.vmware.com/support/developer/PowerCLI/PowerCLI65R1/html/Remove-Snapshot.html

Comentarios