I have a PowerShell script below that checks for file age and sends an alert when the condition is reached. The script works when I run it on the Node. I have other alerts configured for the Node. I just don;t seem to understand how to get or pass the the information from the script to Orion to alert on.
I appreaciate your assistance
$path = 'c:\temp'
$stats = 0
$msg = ''
$days = 3
$hours = 10
$mins = 5
$files = @(Get-ChildItem -Recurse -Path $path -Include '*.*' | ?{ $_.LastWriteTime -lt (Get-Date).AddDays(-$days).AddHours(-$hours).AddMinutes(-$mins) -and $_.psIsContainer -eq $false})
if ($files -ne $null) {
$f_names = [System.String]::Join('|',$files)
$msg = 'Message: ' + $f_names
$stats = $files.Count
} else {
$msg = 'Message: 0 files exceed defined age'
}
Write-Host $msg
Write-Host "Statistic: $stats"