Forum Discussion
Ganesh12
Oct 03, 2019Copper Contributor
"FileSystemWatcher "not able to monitor new files coming in sub directory for network share drive
Hi, I was testing the monitor files using New-Object System.IO.FileSystemWatcher Even I enabled the property the below property,its not working $watcher.IncludeSubdirectories = $true I ...
Kevin_Morgan
Oct 04, 2019Iron Contributor
Can you try the below script ?
$FileSystemWatcher = New-Object System.IO.FileSystemWatcher
$FileSystemWatcher.Path = "C:\RootFolder\TestFolder"
$FileSystemWatcher.IncludeSubdirectories = $true
$FileSystemWatcher.Filter = "*"
$FileSystemWatcher.NotifyFilter = 383
#Register watcher to watch created changes alone.
Register-ObjectEvent -InputObject $FileSystemWatcher -EventName Created -Action {
$Object = "{0} was {1} at {2}" -f $Event.SourceEventArgs.FullPath,
$Event.SourceEventArgs.ChangeType,
$Event.TimeGenerated
$WriteHostParams = @{
ForegroundColor = 'Green'
BackgroundColor = 'Black'
Object = $Object
}
Write-Host @WriteHostParams
}
Other supported EventName(s)
Changed,Renamed,Deleted and Error
Refer this post for more info : https://mcpmag.com/Articles/2015/09/24/Changes-to-a-Folder-Using-PowerShell.aspx?Page=1