xs4eyes

monitor-folder

Jul 13th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. Param (
  2. $Path = "C:\Stuff\",
  3. $SMTPServer = "smtp.gmail.com",
  4. $From = "[email protected]",
  5. $To = @("Jane Doe <[email protected]>", "John Doe <[email protected]>"),
  6. $Subject = "File Addition/Change in "
  7. )
  8.  
  9. $SMTPMessage = @{
  10. To = $To
  11. From = $From
  12. Subject = "$Subject at $Path"
  13. Smtpserver = $SMTPServer
  14. }
  15. $LastWrite = Get-ChildItem $Path -Filter *.* -Recurse | Where { $_.LastWriteTime -ge [datetime]::Now.AddMinutes(-10) }
  16.  
  17.  
  18.  
  19. If ($LastWrite)
  20. { $SMTPBody = "`nThe following files have recently been added/changed:`n`n"
  21. $LastWrite | ForEach { $SMTPBody += "$($_.FullName)`n" }
  22. Send-MailMessage @SMTPMessage -Body $SMTPBody -Credential "[email protected]" -UseSsl
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment