Checkpoint-ing Hyper-V with PowerShell


As I just needed it for my own personal test lab. Here is some Powershell to manipulate checkpoints of multiple VMs at a time.

Warning: Use at you own risk and not in production! Smiley

 

<# Removes specific checkpoints for specific virtual machines

replace the "FAB*" for your VM Name filter

replace the "*2015*" for your Snapshot name filter

remove -WhatIf to "make it so"

#>

Get-VM | Where-Object VMName -Like "Fab*" | Get-VMSnapshot | Where-Object Name -like "*2015*" | Remove-VMSnapshot -WhatIf

 

Output:

What if: Remove-VMSnapshot will remove snapshot "State 0 [04/09/2015 16:17:04]".

What if: Remove-VMSnapshot will remove snapshot "State 1 [04/09/2015 16:17:28]".

What if: Remove-VMSnapshot will remove snapshot "State 2 [04/09/2015 16:17:39]".

What if: Remove-VMSnapshot will remove snapshot "State 0 [04/09/2015 16:17:03]".

What if: Remove-VMSnapshot will remove snapshot "State 1 [04/09/2015 16:17:27]".

 

 

<# Creates Checkpoints (aka snapshots) for specific virtual machines with your name

replace the "FAB*" for your VM Name filter

#>

Checkpoint-VM -Name "FAB*" -SnapshotName "BeforeInstallingUpdates"

image

 

<# Renames specific Checkpoints and attaches date to name

 replace the "FAB*" for your VM Name filter

remove -WhatIf to "make it so"

#>

Get-VM -Name "FAB*" | Rename-VMSnapshot -Name "Before*" -NewName "Toller CP $(Get-date)" -WhatIf

image

 

 

<# Creates Checkpoints for specific virtual machines with a fancy name (counts up and adds date)

replace the "FAB*" for your VM Name filter

replace the "State" for your Checkpoint Prefix

#>

Get-VM -Name "FAB*" | ForEach-Object {Checkpoint-VM -Name $_.Name -SnapshotName "State $((Get-VMSnapshot -VM $_).count) [$(Get-date)]"}

we can run this line multiple times

imageimageimageFirst run, Second run, Third run of above script.

 

<# Reapplies a specific Checkpoint (filtered and sorted by Name ) to specific VMs

replace the "FAB*" for your VM Name filter

replace the "State*" for your Checkpoint Name filter

remove -WhatIf to "make it so"

#>

Get-VM -Name "FAB*" | ForEach-Object {$_ | Get-VMSnapshot | Where-Object Name -like "State*"| Sort Name | Select -First 1 | Restore-VMSnapshot -Confirm:$false -WhatIf}

image

Comments (1)

  1. Anonymous says:

      Recent Releases and Announcements   ·        Microsoft Disaster

Skip to main content