Monday, 13 March 2017

Removing snapshot of multiple Virtual Machines – vSphere PowerCLI

Or, Working with removing multiple virtual machine’s snapshots – vSphere PowerCLI
Or, Removing multiple virtual machine’s snapshots using vSphere PowerCLI
Or, Removing common snapshots from multiple virtual machines in one attempt

Descriptions: Fiends, in my previous article of VMware snapshots series; I explained how to take snapshot of multiple virtual machines in single attempt. Now in this Article, we will see how to remove a common snapshot from multiple virtual machines in one attempt.

This is our daily routine task when we take snapshot of VMs for some maintenance activities and then we have to remove then once the job done.

The very common scenario is “Patch Management”. If you perform patch management, you are enforced to keep a common name of the snapshot you are taking for each VMs due to patch management activity and that’s a good thing you do…Seriously... J

So if you have already taken snapshot of multiple VMs with a common name, you can easily remove those snapshots from all VMs with a single command. We are going to do the same thing in this article.

Scenario:
1. I have three test VMs – TestVM-1, TestVM-2, and TestVM-3
2. Taken a common snapshot on each VMs for a maintenance activity – snapshot name is “Test-Snapshot
3. Want to remove snapshot “Test-Snapshot” from all these three VMs

Useful PowerCLI Commands You can explore to learn more:
PowerCLI C:\> get-help Remove-Snapshot
PowerCLI C:\> get-help Remove-Snapshot -Examples


Steps-1:  Checking for common snapshot on targeted VMs

From vSphere PowerCLI, run the below command to check if the targeted VMs are having common snapshots (Please replace VMs name with yours).

PowerCLI C:\> Get-VM TestVM-1, TestVM-2, TestVM-3 | Get-Snapshot

The Result/Output of the above command
Name                 Description                          PowerState
----                         -----------                                ----------
Test-Snapshot        TestSnapshot-dis               PoweredOff
Test-Snapshot2       TestSnapshot-dis2            PoweredOff
Test-Snapshot        TestSnapshot-dis               PoweredOff
Test-Snapshot2       TestSnapshot-dis2            PoweredOff
Test-Snapshot        TestSnapshot-dis               PoweredOff
Test-Snapshot2       TestSnapshot-dis2            PoweredOff

So, now we have two snapshots on each targeted VMs. In your case, it may be one or more. Here we have to choose the snapshot name that we want to be removed.

In my case, I am taking example snapshot name “Test-Snapshot


Steps-2:  Verifying for selected common snapshot on targeted VMs

From vSphere PowerCLI, run the below command to verify if the targeted VMs are having selected common snapshots (Please replace VMs name with yours)

PowerCLI C:\> Get-VM TestVM-1, TestVM-2, TestVM-3 | Get-Snapshot -Name Test-Snapshot

The Result/Output of the above command
Name                     Description                        PowerState
----                              -----------                        ----------
Test-Snapshot        TestSnapshot-dis               PoweredOff
Test-Snapshot        TestSnapshot-dis               PoweredOff
Test-Snapshot        TestSnapshot-dis               PoweredOff

Now in the above result/output, we can see that the snapshot we had selected “Test-Snapshot” is present on all targeted VMs.

Let’s proceed  with the removal then…


Steps-3:  Prepare the $snapshot1 parameter

From vSphere PowerCLI, run the below command to prepare for the $snapshot1 parameter (Please replace VMs name with yours)

PowerCLI C:\> $snapshot1 = Get-VM TestVM-1, TestVM-2, TestVM-3 | Get-Snapshot -Name Test-Snapshot


Steps-4:  Removing the selected snapshot from all targeted VMs

Run the below command to execute the snapshot removal from all selected VMs

PowerCLI C:\> Remove-Snapshot -Snapshot $snapshot1 -RunAsync

The Result/Output of the above command
If prompted, select the desire option to confirm the execution. In my case, I selected “A” to confirm for all (Yes to All).
--------------------------------------------------------------------------------------------------------------------------
Confirm
Are you sure you want to perform this action?
Performing the operation "Removing snapshot." on target "VirtualMachineSnapshot-snapshot-6931".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): A

Name                                        State                  % Complete Start Time   Finish Time
----                           -----      ---------- ----------   -----------
RemoveSnapshot_Task            Running             0 03:26:10 PM
RemoveSnapshot_Task            Running             0 03:26:31 PM
RemoveSnapshot_Task            Running             0 03:26:34 PM
--------------------------------------------------------------------------------------------------------------------------

That’s it... Selected snapshot has been removed from all targeted VMs.

Cheers, Please write me back if you have any query of feedback on this.

4 comments:

  1. This is only the data I am discovering all around. A debt of gratitude is in order for your website, I simply subscribe your web journal. This is a decent blog.. Tanner Woods

    ReplyDelete
    Replies
    1. Hey, thanks a lot for your feedback. Glad to know that it helped you.. Tech Hungry Readers like you always encourage Techies Sphere to write more and more relevant, easy to understand and unique contents..

      Thanks

      Delete
  2. The blog gives you such emotions that it’s composed for you.
    cpapcleanerandsanitizer.com

    ReplyDelete
    Replies
    1. Thanks for the compliment..enjoy reading..

      Delete