Multiple files + drive health powershell
Reports the age of several named files at once plus the OS drive's free percentage. Pair with multiple capture.value checks — one per JSON path.
Placeholders only. Before running, replace
YOUR_URL with your capture endpoint's POST URL
.
(Open this page from your capture object to have these auto-filled.)
# multi-file.ps1 — report freshness of several files + drive free pct.
$Url = "YOUR_URL/multi-file"
$Files = @{
report = "C:\Reports\daily.csv"
backup = "C:\Backups\latest.bak"
log = "C:\Logs\app.log"
}
$Stats = @{}
foreach ($name in $Files.Keys) {
$path = $Files[$name]
if (Test-Path -LiteralPath $path) {
$age = [int]([DateTime]::UtcNow - (Get-Item -LiteralPath $path).LastWriteTimeUtc).TotalSeconds
$Stats[$name] = @{ exists = $true; age_seconds = $age }
} else {
$Stats[$name] = @{ exists = $false; age_seconds = -1 }
}
}
# Drive free %
$Drive = Get-PSDrive -Name C
$FreePct = if ($Drive.Used + $Drive.Free -gt 0) {
[math]::Round(($Drive.Free / ($Drive.Used + $Drive.Free)) * 100, 1)
} else { 0 }
$Body = (@{
hostname = $env:COMPUTERNAME
files = $Stats
drive_c = @{ free_pct = $FreePct; free_gb = [math]::Round($Drive.Free / 1GB, 2) }
}) | ConvertTo-Json -Compress -Depth 6
Invoke-RestMethod -Uri $Url -Method Post -Body $Body `
-ContentType "application/json" -TimeoutSec 15 | Out-Null
Recommended pairing
Add a capture.value check to this capture object.
Example: json_path = files.report.age_seconds, op = >, threshold = 86400. Add one check per file you care about.
What is the filename?
multi-file.ps1 — this is the suggested name for the downloaded file. Rename freely if you prefer.
site1.erralert.com