PowerCLI / Powershell Script to Delete VMware Snapshots Created by Protect

Version 3

    Purpose

     

    This script is designed for users of Shavlik Protect currently using the features to take snapshots during patch deployment. This script will delete all snapshots created by Shavlik Protect on the targeted VMware host. This can be used as a workaround since the 'automatic' deletion of snapshots will otherwise only occur at the next deployment where a new snapshot is created by Protect.

     

    *Please note* - This script is provided as a possible tool to assist with snapshot deletion. Shavlik does not provide support for this script. It is recommended to test the script prior to use in a production enviornment.

     

    Directions

     

    1) User must download and install PowerCLI from VMware. Information on how to obtain PowerCLI can be found here.

     

    2) Once installed you will need to open a powershell window through PowerCLI, or the cmdlets required will need to be registered. This must be run from a system that can remotely access the VI server. It is not required to be run from the same system where Protect is installed.

     

    3) Execute this command to allow the script to run:

    Set-ExecutionPolicy RemoteSigned

     

    4) Download, extract, and then execute the attached PS1 file 'CleanupShavlikSnapshots.ps1'.

     

    5) The script will prompt for a VI Server (vCenter or standalone Hypervisor), a user credential, and a password. This connects to the VI Server.  Then it runs through a Get-VM command and enumerates each of the existing snapshots for those labeled as Shavlik Protect snapshots. Snapshots labled as Shavlik Protect snapshots will be deleted. The output on screen will show machines that had a snapshot removed in red and those that did not get removed in green.