### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "D:\FTP Data\test\IT-test"
$watcher.Filter = "*.*"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
$smtpServer = "mail.com"
$smtpFrom = "email"
$smtpTo = "email"
$smtpSubject = "Change to Vulcan FTP Folder"
$username = "g"
$password = "pw"
### DEFINE ACTIONS AFTER AN EVENT IS DETECTED
$action = { $smtp = New-Object -TypeName "Net.Mail.SmtpClient" -ArgumentList $smtpServer
$smtp.Credentials = New-Object system.net.networkcredential($username, $Password);
$smtpBody = "[$(Get-Date -Format HH:mm:ss)]`New file arrived: From Vulcan"
$smtp.Send($smtpFrom, $smtpTo, $smtpSubject, $smtpBody)
}
### DECIDE WHICH EVENTS SHOULD BE WATCHED
Register-ObjectEvent $watcher "Created" -Action $action
while ($true) {sleep 30}
Comments