Setting up a file watcher seemed to address the issue and it was actually simple to script.
The following was created to watch the intended file for changes:
1
2
3
4
5
6
7
8
9
|
$watcher = New-Object System.IO.FileSystemWatcher $watcher .Path = 'C:\temp\' $watcher . Filter = 'test1.txt' $watcher .EnableRaisingEvents = $true $changed = Register-ObjectEvent $watcher 'Changed' -Action { write-output "Changed: $($eventArgs.FullPath)" } |
Creating the file watcher took the utilization of the FileSystemWatcher object. This script specifically watches the entire directory and path for changes. An added filer is added to specify the required file.
Next, an ObjectEvent is registered to perform an action when the watcher detects a change event. This script highlights a simple output, however, it could be easily modified to enable sending of an email or performing some other task.
Removing the ObjectEvent is just as easy and can be performed using the following script:
1
|
Unregister-Event $changed .Id |
Source: CANITPRO
Related posts
Reviews
SAMSUNG GALAXY S8 PLUS
The Samsung Galaxy S8 Plus is a beautifully crafted smartphone with nearly no bezel, curvaceous in design and reflects a…
How to: Connect to Exchange Online Using Multi-Factor Authentication
Using PowerShell to manage your Microsoft cloud services like Exchange Online and using multi-factor authentication (MFA) separately is awesome. Using…
Stay connected