Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Alert Based on Last write time

$
0
0

I am writing a script based on the last write time. For the most part it works; however, the script sends out an email everytime the script runs. Ideally, I would like to have the email sent only when the last file written is older than 10 hours.

Below is a copy of the script and I am using a task to call the script. Thanks in advance for the help.

$dir='\\test\testfiles\' 
$sendmail=$false
#$sendmail=$true


$JCFILES = gci -path $dir | where-object {
$_.extension -eq ".pdf" -and ($_.LastWriteTime -lt (get-date).addhours(10) )} 
$JCFILELIST=$JCFILES | sort LastWriteTime | select -last 1 

#	  	  if ($JCFILES){

$strbody=$JCFILELIST
$sendmail=$true
#}		

#$strbody
if($sendmail -eq $true){
$smtpServer = "9.9.9.9"
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = "ELECTRONIC_FOLDER@jcc.com"
$msg.To.Add("jcc@jcc.com")
$msg.Subject = "Please check theElectronic Process"
$msg.Body = "The file below was the last file to process.`n"
$msg.Body += $strbody
$smtp.Send($msg)

}



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>