Peut-être vous êtes confus sur les types d'événements qui sont déclenchés: http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher_events(v=vs.110).aspx
Cela devrait fonctionner, prises à partir du lien ci-dessus et modifiés pour vos besoins:
#By BigTeddy 05 September 2011
#This script uses the .NET FileSystemWatcher class to monitor file events in folder(s).
#The advantage of this method over using WMI eventing is that this can monitor sub-folders.
#The -Action parameter can contain any valid Powershell commands. I have just included two for example.
#The script can be set to a wildcard filter, and IncludeSubdirectories can be changed to $true.
#You need not subscribe to all three types of event. All three are shown for example.
# Version 1.1
$folder = '\\remote\shared' # Enter the root path you want to monitor.
$filter = '*.txt' # You can enter a wildcard filter here.
# In the following line, you can change 'IncludeSubdirectories to $true if required.
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $true;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
# Here, all three events are registerd. You need only subscribe to events that you need:
Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file '$name' was $changeType at $timeStamp" -fore green
Out-File -FilePath c:\scripts\filechange\outlog.txt -Append -InputObject "The file '$name' was $changeType at $timeStamp"}
S'il vous plaît noter qu'une fois que vous Fermez la console powershell, le fichier SystemSystemWatcher est rejeté et ne surveillera plus le (s) dossier (s). Vous devez donc vous assurer que la fenêtre PowerShell reste ouverte. Afin de le faire sans que cela obtenir de votre manière je suggère une tâche planifiée http://blogs.technet.com/b/heyscriptingguy/archive/2011/01/12/use-scheduled-tasks-to-run-powershell-commands-on-windows.aspx
http://gallery.technet.microsoft.com/scriptcenter/Powershell-FileSystemWatche-dfd7084b – Cole9350
FileSystemWatcher Semble fonctionne pas avec le dossier partagé. – ca9163d9
Eh bien, il peut * sembler * ne pas fonctionner, mais cela fonctionne vraiment ... Vous avez juste besoin de connaître le chemin réel – Cole9350