So I have an excellent polling program set up that will report on several different file states such as delete, copy, rename, etc.
I need to create a workflow that will do the following:
- Poll a selected folder one time for a predetermined period of time and then stop. ( I will have the entire script repeat which I will set up later ).
Any help with this would be definitely appreciated. Here is what I have so far:
Function Register-Watcher { param ($folder) $filter = "*.*" #all files $watcher = New-Object IO.FileSystemWatcher $folder, $filter -Property @{ IncludeSubdirectories = $false EnableRaisingEvents = $true } $changeAction = [scriptblock]::Create(' # This is the code which will be executed every time a file change is detected $path = $Event.SourceEventArgs.FullPath $name = $Event.SourceEventArgs.Name $changeType = $Event.SourceEventArgs.ChangeType $timeStamp = $Event.TimeGenerated Write-Host "The file $name was $changeType at $timeStamp" ') $changeAction2 = [scriptblock]::Create(' # This is the code which will be executed every time a file change is detected $path = $Event.SourceEventArgs.FullPath $name = $Event.SourceEventArgs.Name $changeType = $Event.SourceEventArgs.ChangeType $timeStamp = $Event.TimeGenerated Write-Host "The file $name was $changeType at $timeStamp" ') $changeAction3 = [scriptblock]::Create(' # This is the code which will be executed every time a file change is detected $path = $Event.SourceEventArgs.FullPath $name = $Event.SourceEventArgs.Name $changeType = $Event.SourceEventArgs.ChangeType $timeStamp = $Event.TimeGenerated Write-Host "The file $name was $changeType at $timeStamp" ') $changeAction4 = [scriptblock]::Create(' # This is the code which will be executed every time a file change is detected $path = $Event.SourceEventArgs.FullPath $name = $Event.SourceEventArgs.Name $changeType = $Event.SourceEventArgs.ChangeType $timeStamp = $Event.TimeGenerated Write-Host "The file $name was $changeType at $timeStamp" ') Register-ObjectEvent $Watcher -EventName "Changed" -Action $changeAction Register-ObjectEvent $Watcher -EventName "Created" -Action $changeAction2 Register-ObjectEvent $Watcher -EventName "Deleted" -Action $changeAction3 Register-ObjectEvent $Watcher -EventName "Renamed" -Action $changeAction4 } Register-Watcher "c:\temp" Move-Item -Path C:\temp\*.xml -Destination C:\temp1