Single file freshness powershell
Posts the age (in seconds) of one file. Alerts if it's missing or hasn't been updated recently — handy for log files, generated reports, or backup .bak files.
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.)
# file-modified.ps1 — post the age of a single file in seconds.
$Url = "YOUR_URL/file-modified"
$File = "C:\Path\To\Your\file.log"
if (Test-Path -LiteralPath $File) {
$Age = [int]([DateTime]::UtcNow - (Get-Item -LiteralPath $File).LastWriteTimeUtc).TotalSeconds
$Exists = $true
} else {
$Age = -1
$Exists = $false
}
$Body = (@{
hostname = $env:COMPUTERNAME
file = $File
exists = $Exists
age_seconds = $Age
}) | ConvertTo-Json -Compress
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.
json_path = age_seconds, operator = >, threshold = 10800 (3 hours).
What is the filename?
file-modified.ps1 — this is the suggested name for the downloaded file. Rename freely if you prefer.
site1.erralert.com