Posts

Showing posts from April, 2017

Continuously Monitor Folder for New Files with PowerShell as a WindowsService

Recently encountered an old-school application that used a cobbled-together external service to generate reports and deliver to end-users in PDF format. Unfortunately, this service didn't have any error handling other than dropping the intended source content into a flat file in an error directory on the local disk. No monitoring, no notification, just fail and pretend it never happened. As these reports are critical to end users, I needed a way to monitor this directory for any new files and notify someone so that the report could be manually re-generated. After some initial Googling, I decided a quick PowerShell script would be the easiest method to continuously monitor the directory and fire off a notification when a new file is found. I'm admittedly an extreme PowerShell newbie, so I'm sure there are better, cleaner ways to do this, but this works nicely and is stable enough for now until my legacy system is retired in a few months. The below PowerShell script will inst