Hi @jg ,
here is a simple piece of code, which will return since when a file has not been modified and also in will return something if it has been modified within the last day.
$lastDay = (Get-Date).AddDays(-1)
$monitoredFile = "C:\Temp\123.txt"
if ((Get-ItemProperty -Path $monitoredFile -Name LastWriteTime).LastWriteTime -gt $lastDay) {
write-host "File has been modified within the last day"
} else {
write-host "File has not been modified since " (Get-ItemProperty -Path $monitoredFile -Name LastWriteTime).LastWriteTime
}
New-TimeSpan -Start (Get-ItemProperty -Path $monitoredFile -Name LastWriteTime).LastWriteTime -End (Get-Date)
It is pretty simple, but it also calculates the difference since the file has been edited the last time.
You can play with it as you want, you can remove the once-day modification and just calculate the Time span.
When you have it exactly as you want, just put it in a PowerShell monitor (Example the PowerShell MP from cOOKDOWN) and you are ready to go.
Here also a link to the PowerShell MP:
PowerShell Monitoring Management Pack
https://www.cookdown.com/scom-essentials/powershell-authoring/
The MP is free and there is a video that shows you how to cretae a PoSh based monitor.
So you have the script now and a MP that you can use, you just need to put those together.
I hope I could help!
----------
(If the reply was helpful please don't forget to upvote or accept as answer, thank you)
Regards,
Stoyan