-1

I need a way to track updates/modifications to a file in real time and run a batch script when they take place, I have tried this to no avail, which may be due to it being open in the program that is logging output to the file, but

Get-content filename -Tail 0 -Wait

in powershell will show me any updates that happen to the file, is there any way for me to make it launch a script when a change is detected or any other way to do so. I need it to be in either batch or powershell script.

1 Answers1

0

Use a file system watcher and take action on the event.

Powershell FileSystemWatcher

https://gallery.technet.microsoft.com/scriptcenter/Powershell-FileSystemWatche-dfd7084b

This script uses the .net FileSystemWatcher class to subscribe to 'create', 'change' and 'delete' events on files or folders in the NTFS filesystem.It can be used to monitor a folder or folders, and can be modified to perform any action upon the triggering of these events.

Download: FileSystemWatcher.ps1

https://gallery.technet.microsoft.com/scriptcenter/Powershell-FileSystemWatche-dfd7084b/file/42206/1/FileSystemWatcher.ps1

postanote
  • 5,136