Find all snapshots in VmWare vSphere

It's no secret that when you perform backup with Veeam Backup & Replication, sometimes it "forgets" to delete the its snapshots. This leads to the fact that all virtual machine starts to work entirely on snapshot all the time. This is a costly operation, which significantly reduces the performance of the virtual machine.

In addition, system administrators can create snapshot manually and forget about it. We had a case in our company when a virtual server half-year (!!!!!) worked on the snapshot.

Fortunately, VmWare provides a plugin for Powershell, PowerCLI, which you can use to find all these snapshots.

You can download PowerCLI using this link: https://communities.vmware.com/community/vmtn/automationtools/powercli.

After installation of package, you can start PowerCLI from the shortcut or by running common Powershell environment, and import module:

Add-PSSnapin VMware.VimAutomation.Core

Connect to vSphere server:

Connect-VIServer -Server vcenter.domain.local

Get snapshots, filter them by VM power state, sort by creation date and display:

$snapshots = Get-VM | Get-Snapshot | ?{$_.VM.PowerState -ne "PoweredOff"} | sort created;
$snapshots | select VM, name, created, @{Name="VMHost"; Expression={$_.VM.VMHost}} | ft -AutoSize;

Find all snapshots in VmWare vSphere

After you get snapshots, you can delete them in vSphere GUI interface or you can use Powershell:

Get-VM | Get-Snapshot | ?{$_.VM.PowerState -ne "PoweredOff"} | Remove-Snapshot

Just remember to filter the snapshots to not delete something needed.

Tags: vmware (en), powershell (en)

PrintEmail

Add comment


Security code
Refresh