Quantcast
Channel: THWACK: Message List
Viewing all articles
Browse latest Browse all 20625

Re: Advanced File Age Monitor with PowerShell

$
0
0

SAM is expecting 2 lines to come back, one a message (optional), and another a statistic.  Your output doesn't match the format that SAM is after.  I'd do the following:

 

$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(-$minutes) -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 "Statistics: $stats"

 

WIth this, it'll output the file names in the Message, and the file count that exceeds the age will be a statistic, and you can monitor/alert based on that value. One thing to be careful of is the length that the message will get, depending on the number of files in the path.


Viewing all articles
Browse latest Browse all 20625


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>