# backup-freshness.ps1 — age (s) of newest matching file in a folder. $Url = "YOUR_URL/backup" $Folder = "C:\Backups" $Pattern = "*.bak" $Newest = Get-ChildItem -LiteralPath $Folder -Filter $Pattern -File -ErrorAction SilentlyContinue ` | Sort-Object LastWriteTimeUtc -Descending | Select-Object -First 1 if ($Newest) { $Age = [int]([DateTime]::UtcNow - $Newest.LastWriteTimeUtc).TotalSeconds $Body = (@{ hostname = $env:COMPUTERNAME folder = $Folder pattern = $Pattern newest_file = $Newest.Name newest_size_mb = [math]::Round($Newest.Length / 1MB, 1) newest_age_seconds = $Age }) | ConvertTo-Json -Compress } else { $Body = (@{ hostname = $env:COMPUTERNAME; folder = $Folder; pattern = $Pattern newest_file = $null; newest_age_seconds = -1 }) | ConvertTo-Json -Compress } Invoke-RestMethod -Uri $Url -Method Post -Body $Body ` -ContentType "application/json" -TimeoutSec 15 | Out-Null