Support
 
Phone Get Quote
 
Support
 
US: +1 888 720 9500
US: +1 888 791 1189
Intl: +1 925 924 9500
Aus: +1 800 631 268
UK: 0800 028 6590
CN: +86 400 660 8680

Direct Inward Dialing: +1 408 916 9892

How to monitor a folder for new files?

The following is a comparison between monitoring a folder for new files with Windows PowerShell and ADAudit Plus:

Windows PowerShell

Steps to monitor a folder for new files using PowerShell:

  • A .NET class called FileSystemWatcher can be used to monitor folders for any new file. It can be created with a New-Obect cmdlet and it is in in the System.IO namespace.
    $watcher = New-Object System.IO.FileSystemWatcher
  • Apply the necessary parameters to the watcher by assigning values to appropriate object properties, as necessary.

    Example: If the folder has subfolders that need to be monitored, then assign the IncludeSubdirectories property.

    $watcher.IncludeSubdirectories = $true
  • Using the Path property, specify the folder that needs to be monitored. Also, set the EnableRaisingEvents property to $true to raise events when one happens.
    $watcher.Path = 'C:\FolderThat NeedsMonitoring'
    $watcher.EnableRaisingEvents = $true
  • After setting the EnableRaisingEvents property, an action needs to be defined when the event happens. This action can be defined by creating a PowerShell scriptblock. Use the built-in [$event] variable. Every time an event fires, this variable will record information such as the file path and the type of event that fired.
    $action =
        {
        $path = $event.SourceEventArgs.FullPath
        $changetype = $event.SourceEventArgs.ChangeType
        Write-Host "$path was $changetype at $(get-date)"
        }
  • The next step is to register the event. Use the Register-ObjectEvent cmdlet and provide it to the watcher object that was created and to the type of action to monitor. In this case, it will be for new files.
    PS > Register-ObjectEvent $watcher 'Created' -Action $action
    monitor-file-changes-in-windows-with-powershell-2
  • All existing subscribed events can be viewed using Get-EventSubscriber cmdlet.
    PS> Get-EventSubscriber

ADAudit Plus

To monitor a folder for new files,

  • Login to ADAudit Plus → Go to File Audit tab → Under File Audit Reports → Navigate to Files Created report.
    monitor-file-changes-in-windows-with-powershell-1
  • The details you can find in this report are:

    • Name of the file/folder created
    • Which server it was created in
    • Who created it
    • When it was created
    • Object's properties including ACL
    • Client machine from which the file/folder was created
  • Select Export as to export the report in any of the preferred formats (CSV, PDF, HTML, CSVDE and XLSX).
» Start 30-day Free Trial
  • Avoid complex PowerShell-scripting, and simplify AD change auditing with ADAudit Plus.
  •  
  • By clicking 'Get Your Free Trial', you agree to processing of personal data according to the Privacy Policy.
  •  
  • Thanks!
  • Your download is in progress and it will be completed in just a few seconds! If you face any issues, download manually here.

Related Resources

ADAudit Plus Trusted By