Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sushanthmangalore/ae1465adf0997a0b68b7499c80c93e95 to your computer and use it in GitHub Desktop.
Save sushanthmangalore/ae1465adf0997a0b68b7499c80c93e95 to your computer and use it in GitHub Desktop.
$folder = 'D:\Web' # <-- Provided the fully qualified directory path
$filter = '*.txt' # <-- Set this according to your requirements. Matches the file patterns within the directory
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{
IncludeSubdirectories = $true # <-- Set this according to your requirements
}
$onCreated = Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
$path = $Event.SourceEventArgs.FullPath
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file '$name' was $changeType at $timeStamp"
# <-- Plugin code to send the e-mail notification/move the file here.
Send-MailMessage -SmtpServer "localhost" -To "sushanth_mangalore@infosys.com" -From "sushanth_mangalore@infosys.com" -Subject "Hello"
}
@sushanthmangalore
Copy link
Author

E-mail sending can be tested with a fake SMTP server like - https://nilhcem.github.io/FakeSMTP/index.html#

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment