Alert if file is older that x minutes

I need to create a MP that will watch for if a file exists and alert if it does not as well as watch the file age and if it is older than 10 minutes raise an alert. I know there used to be a MP out there that could help with this but I am having trouble finding it at the moment.

We do ours with powershell these days - this is an example of a folder age in hours, writing back to the event log and to SCOM for health

#Parameters
param($threshold, $folder)

#$threshold = ‘4’
#$folder = ‘D:\FTP’

$today = Get-Date
write-output “Todays date is” $today

$limit = (Get-Date).AddHours(-$threshold)
Write-output “Threshold date is” $limit

$folderage = (Get-Item $folder).LastAccessTime
Write-output “Folder Age is”$folderage

if ($folderage -gt $limit){$Result = “Success”} ELSE {$Result = “Error”}
$Result

Write-EventLog -LogName ‘Operations Manager’ -Source ‘Health Service Script’ -EntryType Information -EventId 9100 -Message “Folder Write Monitoring Script Running with the following output:’$folder hasn’t been written to since $folderage , $result”

#API Object
$api = new-object -comObject ‘MOM.ScriptAPI’
$bag = $api.CreatePropertyBag()

$bag.AddValue(‘Health’,$Result)
$bag.AddValue(‘FolderAge’,$FolderAge)
$bag.AddValue(‘Threshold’,$threshold)

#$api.return($bag)

$bag

1 Like