Search code examples
powershellpowercli

VMware PowerCLI - Mass Revert Snapshot


I'm trying to revert an array of VM's (created from C:\esx\vmlist.txt) to snapshot "test" (all were snapshot at the same time with a snapshot named "test").

Here's my script:

Add-PSSnapin VMware.VimAutomation.Core

Connect-VIServer -Server 192.168.10.10 -User root -Password mypass

$VMs = Get-Content'C:\esx\vmlist.txt'

$snapname = Read-Host 'Snapshot Name:'

Get-Snapshot -VM $VMs -Name $snapname -confirm:$false

Any thoughts?


Solution

  • To revert snapshot, you would use Set-VM cmdlet:

    Get-Snapshot -VM $VMs -Name $snapname | Foreach-Object {
        Set-VM -VM $_.VM -Snapshot $_ -Confirm:$false
    }
    

    Just in case: you may want to run this with -WhatIf (instead of -Confirm:$false) first.