site1.erralert.com

← File & folder monitoring

Folder contents (count + size) powershell

Counts files in a folder and reports total size, plus the size of the largest file. Useful for catching backup-folder bloat or pipelines that stopped pruning old data.

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.)
# folder-monitor.ps1 — file count + total size in a folder.

$Url    = "YOUR_URL/folder"
$Folder = "C:\Backups"

if (-not (Test-Path -LiteralPath $Folder)) {
  $Body = (@{ hostname = $env:COMPUTERNAME; folder = $Folder; exists = $false }) | ConvertTo-Json -Compress
} else {
  $Items   = Get-ChildItem -LiteralPath $Folder -Recurse -File -ErrorAction SilentlyContinue
  $Total   = ($Items | Measure-Object Length -Sum).Sum
  $Largest = ($Items | Measure-Object Length -Maximum).Maximum
  $Body = (@{
    hostname        = $env:COMPUTERNAME
    folder          = $Folder
    exists          = $true
    file_count      = $Items.Count
    total_size_gb   = [math]::Round(($Total   / 1GB), 3)
    largest_file_gb = [math]::Round(($Largest / 1GB), 3)
  }) | 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 = total_size_gb, op = >, threshold = 50 (alert if folder exceeds 50 GB).

What is the filename?

folder-monitor.ps1 — this is the suggested name for the downloaded file. Rename freely if you prefer.