First, thanks in advance for any assistance offered.
I am fairly new to PS. I am trying to create a script that will look into a directory to see if the files there are 15 minutes old or older. If it finds any, the script will send an email alert to a Distribution Group. I have this so far...
# Powershell v2.0
# To be used to send alerts for files in FTP folder older than 15 miniutes.
#
$15minutesago = [DateTime]::Now.AddMInutes(-15)
$files = Get-ChildItem c:\temp\log | Where {$_.CreationTime -lt $15minutesago}
$emailFrom = "username@mydomain.com"
$emailTo = "DL-List@mydomain.com"
$subject = "FTP Files Older than 15 minutes"
$body = "There are files 15 minutes old or older on <ServerName><Directory>"
$smtpServer = "smtpserver.mydomain.com"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
What I am having difficulty with is code that will determine IF there are files matching the above criteria. If there are none, the email doesn't get sent. How do I determine that?
Thanks,
TS