# Help with 'LastWriteTime' - Folder Checking script

**URL:** <https://forums.powershell.org/t/help-with-lastwritetime-folder-checking-script/18395>\
**Category:** PowerShell Help\
**Created:** [January 20, 2022, 11:24am UTC](https://forums.powershell.org/t/help-with-lastwritetime-folder-checking-script/18395 "2022-01-20T11:24:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fiorano](https://avatars.discourse-cdn.com/v4/letter/f/858c86/32.png) [@fiorano](https://forums.powershell.org/u/fiorano)\
**Post date:** [January 20, 2022, 11:24am UTC](https://forums.powershell.org/t/help-with-lastwritetime-folder-checking-script/18395/1 "2022-01-20T11:24:21Z")

</div>

Hi Experts,

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

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

$smtp = "email-smtp.eu-west-1.amazonaws.com"
$from = "SFTP@here.com"
$to = "upload@here.com"
$bcc = "them@here.com"
$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 🤨

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

Many thanks  
Fiorano

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 20, 2022, 11:42am UTC](https://forums.powershell.org/t/help-with-lastwritetime-folder-checking-script/18395/2 "2022-01-20T11:42:15Z")

</div>

Tim,  
Welcome to the forum. 👋🏽

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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:19pm UTC](https://forums.powershell.org/t/help-with-lastwritetime-folder-checking-script/18395/3 "2024-05-16T20:19:41Z")

</div>


