← script library

Hyper-V Virtual Machine Snapshot Management Script

Hyper-VJanuary 10, 2025

Managing Hyper-V virtual machines efficiently is crucial for maintaining a productive environment. In this post, we'll share a useful PowerShell script that helps to create, list, and remove snapshots of Hyper-V virtual machines. This script can simplify your VM management tasks and enhance the way you handle backups and recovery points. Before we begin, ensure you have the necessary permissions to run these commands in your Hyper-V environment.

powershell
$VMName = 'YourVirtualMachineName'
$SnapshotName = 'Snapshot_' + (Get-Date -Format 'yyyyMMdd_HHmmss')
Checkpoint-VM -Name $VMName -SnapshotName $SnapshotName
Write-Host "Snapshot '$SnapshotName' created for VM '$VMName'"

$Snapshots = Get-VMCheckpoint -VMName $VMName
if ($Snapshots) {
    $Snapshots | ForEach-Object {
        Write-Host "Snapshot Name: $($_.Name) - Created on: $($_.CreationTime)"
    }
} else {
    Write-Host "No snapshots found for VM '$VMName'."
}

$SnapshotToRemove = 'Snapshot_YourNameToRemove'
Remove-VMCheckpoint -VMName $VMName -Name $SnapshotToRemove
Write-Host "Snapshot '$SnapshotToRemove' removed successfully from VM '$VMName'."

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.