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.
Perquisites: –
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:
Access rights in vCenter for creating and deleting snapshots.
Taking the Snapshot: –
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.

- Connect vCenter
connect-viserver vcentrIP/Hostname
The vCenter username and password are requested for authentication. After successful authentication, PowerShell commands are executed.
- 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.




Deleting the Snapshot: –
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.


Creating a snapshot with memory:-
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.
