-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFSWatcher.ps1
32 lines (27 loc) · 1.51 KB
/
FSWatcher.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
$FTBM = 'C:\Users\Cyber\Desktop\FSWatcher\tobemonitored'
$FLTR = '*.*'
$watcher = New-Object IO.FileSystemWatcher $FTBM, $FLTR -property @{IncludeSubDirectories = $false; NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
Register-ObjectEvent $watcher Created -SourceIdentifier FileCreated -Action {
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "This file: $name, was $changeType at $timeStamp!"
Out-File -filepath 'C:\Users\Cyber\Desktop\FSWatcher\logs\CreationLogs.txt' -append -inputobject "This file: $name, was $changeType at $timeStamp!"
}
Register-ObjectEvent $watcher Deleted -SourceIdentifier FileDeletion -Action {
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "This file: $name, was $changeType at $timeStamp!"
Out-File -filepath 'C:\Users\Cyber\Desktop\FSWatcher\logs\DeletionLogs.txt' -append -inputobject "This file: $name, was $changeType at $timeStamp!"
}
Register-ObjectEvent $watcher Changed -SourceIdentifier FileChange -Action {
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "This file: $name, was $changeType at $timeStamp!"
Out-File -filepath 'C:\Users\Cyber\Desktop\FSWatcher\logs\ChangeLogs.txt' -append -inputobject "This file: $name, was $changeType at $timeStamp!"
}
#Unregister-Event FileDeletion
#Unregister-Event FileChange
#Unregister-Event FileCreated