Skip to content

Instantly share code, notes, and snippets.

@jimbo8098
Created June 18, 2021 15:50
Show Gist options
  • Save jimbo8098/2b9092671f2b5310f481f7eca772c86c to your computer and use it in GitHub Desktop.
Save jimbo8098/2b9092671f2b5310f481f7eca772c86c to your computer and use it in GitHub Desktop.
Revert Hyper-V VMs to their Last Commit
#Amend to taste
$RestoreVMs=@(
"Ubuntu Throwaway 1",
"Ubuntu Throwaway 2",
"Ubuntu Throwaway 3",
"Windows Throwaway 1",
"Windows Throwaway 2"
)
foreach($vm in $RestoreVMs) {
$vmObj = Get-VM -Name $vm
if ( $vmObj.Status -eq "Operating normally" -and $vmObj.State -eq "Running") {
$checkpointToRestore = (Get-VMCheckpoint -VMName $vmObj.Name | Sort-Object -Descending -Property CreationTime)[0]
Restore-VMCheckpoint -Name $checkpointToRestore.Name -VMName $vmObj.Name -Confirm
#Start-Sleep -s 10
if((Get-VM -Name $vmObj.Name).State -ne "Running") {
Start-VM $vmObj.Name
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment