-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow-directorychanges.ps1
More file actions
35 lines (28 loc) · 947 Bytes
/
show-directorychanges.ps1
File metadata and controls
35 lines (28 loc) · 947 Bytes
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
33
34
35
# monitor a directory for changes and report them
function Show-DirectoryChanges{
param([string]$directory = ($throw "Needs a directory path to monitor."),
[switch]$exit)
if($exit){
Unregister-Event $changed.Id
Unregister-Event $created.Id
Unregister-Event $deleted.Id
Unregister-Event $renamed.Id
return
}
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = $directory
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
$changed = Register-ObjectEvent $watcher "Changed" -Action {
write-host "Changed: $($eventArgs.FullPath)"
}
$created = Register-ObjectEvent $watcher "Created" -Action {
write-host "Created: $($eventArgs.FullPath)"
}
$deleted = Register-ObjectEvent $watcher "Deleted" -Action {
write-host "Deleted: $($eventArgs.FullPath)"
}
$renamed = Register-ObjectEvent $watcher "Renamed" -Action {
write-host "Renamed: $($eventArgs.FullPath)"
}
}