Monitor any Folder for Files and Take Action

Adam Bertram

Adam Bertram

Read more posts by this author.

I routinely need to monitor a certain folder for files on a server. It’s usually some LOB application that places reports into a certain folder that can’t be changed in the app but the reports need to actually be in a different folder. After created too many scheduled tasks over the years and being forced to only check every minute I decided to learn about creating WMI event subscriptions more specifically permanent WMI event subscriptions.

With permanent WMI event subscriptions I can set up a monitor to always be running in WMI that checks (down to 1 second) if a file shows up in a folder on the server. It turns out it’s not quite a simple as I anticipated and I really didn’t want to have to go Googling for code snippets every time I wanted to create one so I created a Powershell module called FileMonitor. After you import the module you’ll have a few functions available to you; Get-FileMonitor, Remove-FileMonitor and New-FileMonitor. You can probably guess what they do.

Download it, import it and play around with it. Let me know if you have any problems and I’d be glad to tweak it.

Subscribe to Adam the Automator

Get the latest posts delivered right to your inbox

Looks like you're offline!