Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Param (
- $Path = "C:\Stuff\",
- $SMTPServer = "smtp.gmail.com",
- $From = "[email protected]",
- $To = @("Jane Doe <[email protected]>", "John Doe <[email protected]>"),
- $Subject = "File Addition/Change in "
- )
- $SMTPMessage = @{
- To = $To
- From = $From
- Subject = "$Subject at $Path"
- Smtpserver = $SMTPServer
- }
- $LastWrite = Get-ChildItem $Path -Filter *.* -Recurse | Where { $_.LastWriteTime -ge [datetime]::Now.AddMinutes(-10) }
- If ($LastWrite)
- { $SMTPBody = "`nThe following files have recently been added/changed:`n`n"
- $LastWrite | ForEach { $SMTPBody += "$($_.FullName)`n" }
- Send-MailMessage @SMTPMessage -Body $SMTPBody -Credential "[email protected]" -UseSsl
- }
Advertisement
Add Comment
Please, Sign In to add comment