Hyper-V checkpoints can help an administrator roll back changes in the event of a problem by taking point-in-time...
images of Hyper-V VM. For example, you can take checkpoints of a VM, perform your application testing and revert the checkpoint to a known state if you need to retest. Although you can use Hyper-V Manager to perform checkpoint tasks, it's easier to do the same tasks using PowerShell.
By default, Hyper-V checkpoints aren't enabled on VMs. In order to execute the PowerShell commands below, you'll be required to enable checkpoints on the VMs. You can use the Hyper-V Manager to enable checkpoints for a VM, but you can also execute the Set-VM PowerShell cmdlet. To enable checkpoints for a single VM, execute the Set-VM –Name SQLVM –CheckPointType Enable PowerShell command. Next, run Set-VM –Name SQLVM –CheckPointType ProductionOnly to configure the VM to use a production checkpoint -- first introduced in Hyper-V 2016.
Once you have enabled checkpoints for a VM, you can execute the below PowerShell commands to take checkpoints or revert to a checkpoint of your choice.
Create a checkpoint
To create a checkpoint, use the CheckPoint-VM PowerShell cmdlet. Just executing CheckPoint-VM –Name SQLVM will create a checkpoint for an SQLVM. If you need to take another checkpoint, execute the same command. Note that when you take a checkpoint, Hyper-V creates a checkpoint entry with the date and time when the checkpoint was taken.
To list all of the Hyper-V checkpoints for a VM, use Get-VMSnapshot –VMName SQLVM.
Note that the Checkpoint-VM PowerShell cmdlet doesn't support taking checkpoints for a VM running on a remote Hyper-V host. If you need to perform a checkpoint for a remote VM, interact with the remote VM using the Get-VM PowerShell cmdlet and then pipe the Checkpoint-VM cmdlet as shown in the command below:
Get-VM Remote_SQLVM –ComuterName RemoteHyper-VHost | Checkpoint-VM
By using the command above, you are performing a checkpoint for a VM that is running on RemoteHyper-VHost.
To restore or revert to a checkpoint for a VM, use the Restore-VMSnapshot PowerShell cmdlet. If you would like to restore an SQLVM to a previous checkpoint, execute the PowerShell commands below:
$ThisVM = “SQLVM”
$ThisVM | Get-VM | Get-VMSnapshot –Name “SnapshotName” | Restore-VMSnapshot –Confirm:$False
Note that you will be required to stop the VM before performing the checkpoint restore operation.
Learn about the different Hyper-V checkpoints
Navigate the new features in Hyper-V 2016
Perform a Hyper-V health check with PowerShell
Dig Deeper on Microsoft Hyper-V management
Related Q&A from Nirmal Sharma
Use System Center Virtual Machine Manager and PowerShell to make logical network management easy. Execute a script to display network virtualization ... Continue Reading
Hyper-V replication is easy to use, but there are a number of steps you should take during Hyper-V replication setup to ensure you stay abreast of ... Continue Reading
Manage Hyper-V clusters more easily with PowerShell cmdlets and scripts that automate the retrieval and display of node information, including node ... Continue Reading