Help with 'LastWriteTime' - Folder Checking script

Hi Experts,

Im using the following script on our sFTP server to notify team members when a new file is uploaded.

$SECURE_KEY = $(ConvertTo-SecureString -AsPlainText -String $AWS_SECRET_KEY -Force)
$creds = $(New-Object System.Management.Automation.PSCredential ($AWS_ACCESS_KEY, $SECURE_KEY))

$smtp = ""
$from = ""
$to = ""
$bcc = ""
$subject = "SFTP Alert!"

$Path = "D:\DATA\YourData\"  
$excluded = @("*.log")

$File = Get-ChildItem $Path -Recurse -exclude $excluded | Where { $_.LastWriteTime -ge [datetime]::Now.AddMinutes(-10) }
If ($File)
{ $SMTPBody = "Hello Team <br /> The following data files have recently been uploaded: <br />"
$File | ForEach { $SMTPBody += "$($_.FullName)<br />" }
Send-MailMessage -From $from -To $to -Bcc $bcc -Subject $subject -Body $SMTPBody -BodyAsHtml -SmtpServer $smtp -Credential $creds -UseSsl -Port 587 

Its working but a bit too well. Quite often we will get notification even when there is not file copied. A few times lately, a notification has been sent when the folder timestamp has modified (no file transferred) - also I cant see what is causing the folder to get a modified timestamp :face_with_raised_eyebrow:

Is there a way to only monitor for files coming into the folder?

Many thanks

Welcome to the forum. :wave:t4:

You can use the parameter -File to limit the output of Get-ChildItem to only files - no directories.