Created
November 21, 2018 09:18
-
-
Save peterhynes/450f14c8982bfb6ceeb79b3bdeb8be86 to your computer and use it in GitHub Desktop.
Powercli script to take delete or revert snapshots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Script to manage snapshots - take snaps - delete snaps - revert to snaps | |
| #By Peter Hynes 06-11-2018 | |
| #Comment out any section you do not want to run | |
| #Replace vcentername with the name of the vcenter you are working in. | |
| #Replace vm1 vm2 vm3 with the name of the vms you are working with - you can add as many vms as needed here | |
| #Replace snapshotname and shapshot description with an appropriate name and description | |
| connect-viserver vcentername | |
| $vms = ("vm1", "vm2", "vm3",) | |
| #section to delete snapshots | |
| #Write-Host "Removing Snaps" -foregroundcolor Green | |
| #Foreach ($vm in $vms) { | |
| # Write-Host "Working on $vm" -foregroundcolor Green | |
| # get-vm $vm | Get-Snapshot | Remove-Snapshot -Confirm:$false | |
| # } | |
| #Section to Take snapshots | |
| #Write-Host "Taking new Snaps" -foregroundcolor Green | |
| #Foreach ($vm in $vms) { | |
| # Write-Host "Working on $vm" -foregroundcolor Green | |
| # get-vm $vm | New-Snapshot -Name snapshotname -Description snapshotdescription -Confirm:$false | |
| # } | |
| #Section to revert to snapshot | |
| Write-Host "Reverting to Snaps" -foregroundcolor Green | |
| Foreach ($vm in $vms) { | |
| Write-Host "Working on $vm" -foregroundcolor Green | |
| Set-VM -VM $vm -SnapShot snapshotname -Confirm:$false | |
| Start-VM -VM $vm -Confirm:$false | |
| } | |
| Write-Host "Script complete" -foregroundcolor Green |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment