Powershell FileSystemWatcher

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. 

4.6 Star
17,847 times
Add to favorites
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question

  • How can I watch several Folders
    1 Posts | Last post May 14, 2018
    • Your Trigger is great but I would like to watch several Folders. Certain Scripts should be started by Arriving of a file within one of those Folders. Is it possible to use Case Statement within it? If yes Please make an example.
  • Server 2016
    4 Posts | Last post May 08, 2018
    • Hi 
      I have installed this script on a test server in a test domain, but it does not seem to be working. 
      Do I also need to get a GPO for logging read, write and delete of objects? 
      I also noticed that you have the original settings for logging plus an enhanced setting for logging, which should I use? 
    • Edited to add - have taken another shufty at the script, and changed subdirectory flag to $true
      Seems to be working, will monitor and shout out if not. 
    • It is working fine, thanks.
      What do I need to have it log the name of the (offending) user doing the changes? 
    • Why do this stop working if I close the PS window it is running in? 
  • Only works the first time?
    2 Posts | Last post April 27, 2018
    • Does anyone know why it's only monitoring the first change/delete/create then does not report any additional updates? My events were never unregistered in fact I will get an error if I try to re-register them since they are currently running.
    • I figured it out. I did not have the c:\scripts\filechange\ directory created already so it was erroring out while looking for this and interrupted further detection. You can either delete the out-file line or make sure that directory is created ahead of time.
  • monitor folders about no changes
    1 Posts | Last post March 14, 2018
    • Hi,
      I need to monitor folders about no changes for two hours and send an e-mail afterwards. I am not sure what to adjust in the script.
  • WinXP
    1 Posts | Last post January 26, 2018
    • I checked, it works on WinXP SP3 with PowerShell 2.0 .Net2.0SP1. Thank you!
  • File Owner or who changed it
    2 Posts | Last post October 10, 2017
    • I have been using this and works great, I just would like to know how to modify it to record the name of the user that changed the file. I am monitoring a fileshare. 
    • Did you ever find a way to add a user name to this?
  • File Change always comes twice !!!
    1 Posts | Last post March 24, 2016
    • now is every day just ne new log file created yyyy_MM_dd.txt fit only change problem I have yet. !! the create (file is box folder XML) is green written an entry and additional 2x change what I want !!! when I change the file in the folder XML should there be change message which comes but twice !! if I file delete as desired only 1x red message delete reported! that's OK.
      I do not want is to create the change message in and not always 2 times .. written somewhere too much I think ...
  • Hi, how do I get the script to run automatically?
    2 Posts | Last post March 23, 2016
    • I would like that if an xml file comes in, automatically log.txt is created! currently I need to start powershell manually to create a log.txt
      my script:
      Get-ChildItem -Path 'D:\Kemal test xml\XML' | SELECT CreationTime, name | Format-Table -AutoSize | Out-File -filepath ('D:\Kemal test xml\Logfiles\log'+((Get-Date).ToString("yyyy_MM_dd"))+'.txt')
      an result is:
      log2016_03_23.txt (text Document)
    • now everyone is entry 3 times written to the log.txt! 2x change and 1x create ...
      it should make only 1x create or 1x change or 1x delete ...!!
      plz help!! 
      i use the script FileSystemWatcher!
  • How to add a file move / rename
    1 Posts | Last post November 23, 2015
    • Thank you for your script, I'm wondering how I could add one piece of functionality to it, 
      When the file created goes off, that it would copy to another directory, and rename the existing file to yyyyMMdd format. 
      I don't know where to put that in, or if I just need to create something new? I love the script though and it's working flawlessly for updating that things are changing. 
      Thank you. 
  • new folders within folders
    1 Posts | Last post November 10, 2015
    • Hi.
      If I create new folders within the watched folder, it doesn't keep track of any new files.
      Is this expected or am I doing something wrong?
1 - 10 of 25 Items