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;
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.
Join the Jar Tippers on Patreon
It takes a lot of time to write detailed blog posts like this one. In a single-income family, this blog is one way I depend on to keep the lights on. I'd be eternally grateful if you could become a Patreon patron today!Become a Patron!
Subscribe to Adam the Automator
Get the latest posts delivered right to your inbox