I am very new to this, the script I have is beyond me. I need this script to find a specific file that is older than 5 minutes and email me. The script does email me with files that are older than 5 minutes, but I need to look for a specific file. What do I need to add or change to do this?
$src="c:\test\"
$sendmail=$false
Get-ChildItem -path $src -Recurse |
Foreach-Object {
#write-host $_.fullname
$dtdiff = New-TimeSpan ($_.CreationTime) $(Get-Date)
if ($dtdiff.minutes -gt 5)
{$strbody=$strbody +$_.fullname+ " - Created Time: " +$_.CreationTime +"`r`n"
$sendmail=$true
}
}
#$strbody
if($sendmail -eq $true){
# Email components
$strFromAddress = "it@it.com"
$strToAddress = "me@it.com"
$strMessageSubject = "REPORT"
$strMessageBody = $strbody
$strSendingServer = "mail.it.com"
# Email objects
$objSMTPMessage = New-Object System.Net.Mail.MailMessage $strFromAddress, $strToAddress, $strMessageSubject, $strMessageBody
$objSMTPClient = New-Object System.Net.Mail.SMTPClient $strSendingServer
$objSMTPClient.Send($objSMTPMessage)}