Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 9

Monitor Moving Log Files with Powershell

I am new to Powershell, I have managed to create powershell script to check modified dates, text in Log Files, request to HTTP Services, but I am having a difficult time trying to create a monitor that will pick up on whether or not a "Clean Up.log" File has moved with in the last minute. I am hoping I can get some assistance on this effort. Thanks in advanced.

The file moves every second, but the modified date in the windows folder doesn't reflect that.

This is the closest I could get to it, but again i believe this still uses that "Modified date" information vs the Real Time Movement with in the log file.

$lastDay = (Get-Date).AddDays(-1)
$monitoredFile = "C:\Test.xml"
while ($true)
    if ((Get-ItemProperty -Path $monitoredFile -Name LastWriteTime).LastWriteTime -gt $lastDay)
        write-host "File has been modified within the last day"
        write-host "File has not been modified since " (Get-ItemProperty -Path $monitoredFile -Name LastWriteTime).LastWriteTime
0 Kudos
0 Replies