Categories: VMware

Creating and Deleting Multiple VM Snapshots in vSphere with PowerCLI.

While VM snapshots can be created using the vSphere UI or other methods, manually taking multiple snapshots can be quite time-consuming. To streamline the process and save time, Power Shell can be used to easily take or delete multiple snapshots. This method also helps minimize errors that may occur when performing the same task manually multiple times.

The PowerShell Command Line Interface and the vSphere PowerShell module.

For detailed steps on how to install the vSphere Power CLI, kindly refer to the following link:

https://docs.vmware.com/en/VMware-PowerCLI/latest/powercli/GUID-ACD2320C-D00F-4CCE-B968-B3C41A95C085.html

Access rights in vCenter for creating and deleting snapshots.

I am preparing to take screenshots of the test and test1 virtual machines.

You can see below that. Currently, no snapshot is available on the test VM.

Prepare an Excel workbook with a list of VM names for which you will be taking snapshots.

I have specified the names of the test and test1 virtual machines.

The Power shell scripts can be downloaded from the link provided below:-

https://github.com/Dineshk1205/Snapshot-PowerCLI.git

After the file has been downloaded, make sure to change the file path to match your file path and update the name of the snapshot accordingly.

For the deletion of files, you may update the file path with your file path name to delete snapshots taken.

  1. Connect vCenter

connect-viserver vcentrIP/Hostname

The vCenter username and password are requested for authentication. After successful authentication, PowerShell commands are executed.

  1. Create a VM snapshot.

Grant the necessary execute permission to the snaptake.ps1 file by using the command chmod +x snaptake.ps1.

Run snaptake.ps1 file.

./snaptake.ps1

You can see the screenshot below. Snapshot for the test & test1 VM created.

You must assign the appropriate execute permissions to the snapdel.ps1 file with the command (chmod +x snapdel.ps1).

Before proceeding to run the script, make sure that the file path is correctly specified.

Run snapdel.ps1 script

./snapdel.ps1

You can see in the Vcenter task list that the test & test1 Snapshots were deleted successfully.

If you want to take a snapshot with memory, add -Memory at the end of the 3rd line in a script.

Run script

./snaptake.ps1

If you want to delete the snapshot, just run the snapdel.ps1 script.

Dineshreddy Kayithi

Rooted in a solid academic foundation with a Bachelor's Degree in Information Technology, my career has been deeply entrenched in designing, deploying, and managing enterprise-grade infrastructure across virtualization, cloud-native, and containerized environments. Industry certifications from VMware, AWS, Microsoft, and Kubernetes validate my hands-on expertise in architecting scalable, resilient systems spanning hypervisors, public/hybrid cloud platforms, and container orchestration frameworks. I'm driven by a relentless pursuit of emerging technologies — translating them into production-ready solutions that solve complex operational challenges.

Share
Published by
Dineshreddy Kayithi

Recent Posts

Red Hat OpenShift VM Micro-segmentation Using MultiNetworkPolicy

OpenShift Virtualization allows virtual machines (VMs) to run natively on Kubernetes alongside container workloads. Using…

2 weeks ago

Red Hat OpenStack Services on OpenShift (RHOSO)

Red Hat OpenStack Services on OpenShift (RHOSO) provides the foundation to build a private or public…

4 weeks ago

Kubernetes Cluster Deployment

Kubernetes (often shortened to “K8s”) is an open-source system for automating the deployment, scaling, and…

1 month ago

Ceph cluster on a single machine

Ceph is an open-source, distributed storage platform that provides object, block, and file storage in…

1 month ago

vSphere to OpenShift VM Migration

Prerequisites Red Hat OpenShift cluster deployed and operational You can refer to my earlier post…

2 months ago

Installing OpenShift 4.21 in an air-gapped on-premises/BareMetal environment using Agent-based deployment

Agent-Based Installation The Agent-based installation method provides the flexibility to boot your on-premise servers in…

3 months ago