Skip to main content

CWM - Automate - ESXi - Snapshot Delete Param

Summary

This script can be used to delete a snapshot of a machine hosted on an ESXi host server. It utilizes the PowerCLI Module to perform the required action.

Note: The script must be executed from a machine that can reach the ESXi Host.

Prerequisites

  • .NET Framework 4.7.2+ (Release: 461808)
  • PowerShell v5.1+

Sample Run

  1. Create a credential entry on the client's password tab to connect with the ESXi Host. It must be an admin/root-level credential.
  2. Add either the public or private IP address of the ESXi Host in the URL section of the entry. Do not use HTTP or HTTPS along with the IP address.
    e.g.,
    http://10.0.0.4/io ==> Incorrect
    10.0.0.4 ==> Correct
  3. Sample Screenshot:
    Sample Screenshot
  4. Add proper parameters while executing the script.
    Parameters Screenshot
    The Password_Title should be the title of the password entry created in the first step. In the above example, the script will attempt to remove the snapshot SnapShot 12-12-1997 from the virtual machine Test VM 1. It will not generate any alerts on failure.
  5. For alerting on failure:
    Alerting Screenshot
    In this example, the script will attempt to remove the snapshot SnapShot 12-12-1997 from the virtual machine Test VM 1. Additionally, the script will create a ticket if it fails to deliver the desired results and will send a failure email to the user running/scheduling the script. Either or both of the alerting options can be used.

Dependencies

CWM - Automate - Script - ESXi - Snapshot Create [Param]

Note: This script can be scheduled with proper parameters to remove the snapshot created by the CWM - Automate - Script - ESXi - Snapshot Create [Param] script after @Hours_To_Keep@ hours.

Variables

NameDescription
ProjectNameESXi_RemoveSnapshot
WorkingDirectoryC:/ProgramData/_automation/script/ESXi_RemoveSnapshot
ESXiHostIP Address of ESXi Host, fetched from the password entry
UserNameUserName to use to connect with the ESXi Host, fetched from the password entry
PasswordPassword to use to connect with the ESXi Host, fetched from the password entry
psoutOutput of the PowerShell script deleting the Snapshot

User Parameters

NameExampleRequiredDescription
SnapshotNameCW-Automate-Temp-Snapshot_20230501_081958TrueName of the Snapshot to remove
VMNameDEV_Test-win10TrueName of the virtual machine from which to remove the snapshot
Password_TitleEsxi_HostTrueTitle of the password entry to use to connect with the ESXi Host
Ticket_On_Failure1False1 to enable ticketing for the script's failure.
Email_On_Failure1False1 to enable email alerts for the script's failure. The email will be sent to the user running/scheduling the script.

Output

  • Script Logs
  • Ticket (If Enabled)
  • Email to the user running the script (if Enabled)

Alerting

Subject: Snapshot deletion failed for the VM @VMName@

Body:

For Prerequisites Validation Failure:

Automate failed to delete the Snapshot @SnapShotName@ from the virtual machine @VMName@.
The prerequisite check failed for %ComputerName%, and the `ESXi - SnapShot Delete [Param]` script cannot be executed against %ComputerName%.
Please execute the script against another machine in the network to delete the Snapshot.
Prerequisite Validation Command Output: %ShellResult%

For Snapshot Deletion Failure:

Automate failed to delete the Snapshot @SnapShotName@ from the virtual machine @VMName@. Please review manually.
PowerShell script result: @psout@