- The Workflow
- The Implementation
A common L3 infrastructure issue is technicians taking a VM checkpoint before an update and forgetting to delete it. This script scans for stale snapshots and fires an alert to a Microsoft Teams or Slack webhook.
1. The Workflow
The script performs the following steps:
- Discovery: Scans the local Hyper-V host for all active checkpoints.
- Evaluation: Compares the creation date of the snapshot against a 7-day threshold.
- Alerting: If stale snapshots exist, it constructs a JSON payload and POSTs it to a designated webhook URL.
2. The Implementation
$ThresholdDate = (Get-Date).AddDays(-7)
$StaleSnapshots = Get-VM | Get-VMSnapshot | Where-Object { $_.CreationTime -lt $ThresholdDate }
if ($StaleSnapshots) {
$Payload = @{ text = "⚠️ Orphaned Snapshots Detected on $env:COMPUTERNAME" } | ConvertTo-Json
Invoke-RestMethod -Uri "[https://your-webhook.url](https://your-webhook.url)" -Method Post -Body $Payload -ContentType "application/json"
}