Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. ### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
  2. $watcher = New-Object System.IO.FileSystemWatcher
  3. $watcher.Path = "D:\FTP Data\test\IT-test"
  4. $watcher.Filter = "*.*"
  5. $watcher.IncludeSubdirectories = $true
  6. $watcher.EnableRaisingEvents = $true
  7.  
  8.  
  9. $smtpServer = "mail.com"
  10. $smtpFrom = "email"
  11. $smtpTo = "email"
  12. $smtpSubject = "Change to Vulcan FTP Folder"
  13. $username = "g"
  14. $password = "pw"
  15.  
  16. ### DEFINE ACTIONS AFTER AN EVENT IS DETECTED
  17. $action = { $smtp = New-Object -TypeName "Net.Mail.SmtpClient" -ArgumentList $smtpServer
  18. $smtp.Credentials = New-Object system.net.networkcredential($username, $Password);
  19. $smtpBody = "[$(Get-Date -Format HH:mm:ss)]`New file arrived: From Vulcan"
  20. $smtp.Send($smtpFrom, $smtpTo, $smtpSubject, $smtpBody)
  21. }
  22. ### DECIDE WHICH EVENTS SHOULD BE WATCHED
  23. Register-ObjectEvent $watcher "Created" -Action $action
  24. while ($true) {sleep 30}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement