This script will check for files that exists at least 10 minutes ago.
[powershell]Param (
[string]$Path = "O:\Path\",
[string]$SMTPServer = "Server.com",
[string]$emailSmtpServerPort = "25",
[string]$emailSmtpUser = "test@test.com",
[string]$emailSmtpPass = "Password",
[string]$From = "test@test.com",
[string]$enableSSL = $true,
[string[]]$To = ("test@test.com","helpme@test.com"),
[string]$Subject = "test"
)
$SMTPMessage = @{
To = $To
From = $From
Subject = "$Subject at $Path"
Smtpserver = $SMTPServer
}
$File = Get-ChildItem $Path | Where { $_.CreationTime -ge [datetime]::Now.AddMinutes(-10) }
If ($File)
{ $SMTPBody = "`nThe following files have recently been added/changed:`n`n"
$File | ForEach { $SMTPBody += "$($_.FullName)`n`n" }
Send-MailMessage @SMTPMessage -Body $SMTPBody[/powershell]