June 2025
Beginner to intermediate
473 pages
13h 30m
English
If you use Microsoft Hyper-V as a virtualization system, you run the risk of accumulating old snapshots that will eat up storage space. The following PowerShell script deletes all snapshots older than 30 days:
# Sample file delete-old-snapshots.ps1$days = 30$aMonthAgo = (Get-Date).AddDays(-$days)foreach ($snapshot in Get-VMSnapshot -VMName *) { if ($snapshot.CreationTime -lt $aMonthAgo) { $vmname = $snapshot.VMName $snapname = $snapshot.Name Write-Output "Delete '$snapname' of VM '$vmname'" Remove-VMSnapshot -VMName $vmname -Name $snapname -Confirm }} The script assumes that Hyper-V is installed with all the administration tools on your Windows machine, which automatically makes the Hyper-V PowerShell ...
Read now
Unlock full access