Monitor File or Directory Changes with PowerShell and Email Changes

I had a need to monitor a file/directory for changes, or more specifically entries into an error log by an application. I wanted a trigger on file change using a PowerShell or some other script, since the application didn’t have alerting capabilities built in. I wanted a script to check read the log file and send an email when the file changes containing what was changed, or in this case what the error was. You can tweak the script to monitor a directory or specific file, and customize the email with the file name or more. Either way this is the basic script. Schedule a task in Task Scheduler (Windows 7) or Scheduled Tasks (Windows XP) to run at login for that specific user, and make sure it never terminates or times out. Set your application to run:

2 comments

  1. When I run the script I get this error
    Unexpected token ‘function’ in expression or statement.
    At C:\Data\Scripts\PowerShell\SendFileAlert\SendFileAlert.ps1:19 char:12
    + 10 function <<<< sendMail($s) {
    + CategoryInfo : ParserError: (function:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken
    Can you help?
    Thanks!

Leave a comment

Your email address will not be published. Required fields are marked *