Created
September 8, 2017 18:33
-
-
Save deekayen/d2b577e06acd279d30ed32d92b53d3a8 to your computer and use it in GitHub Desktop.
Send an email alert with a list of files in a path older than 5 minutes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set-ExecutionPolicy Unrestricted | |
$src1="\\processing\files" | |
$sendmail=$false | |
Get-ChildItem -path $src1 -Recurse -File | | |
Foreach-Object { | |
$dtdiff = New-TimeSpan ($_.CreationTime) $(Get-Date) | |
if ($dtdiff.minutes -gt 5) { | |
$strbody=$strbody +$_.fullname+ " - Last Modified Time: " +$_.LastWriteTime +"`r`n" | |
$sendmail=$true | |
write-host $_.fullname | |
} | |
} | |
if($sendmail -eq $true) { | |
# Email components | |
$strFromAddress = "alert@examplecom" | |
$strToAddress = "soc@example.com" | |
$strMessageSubject = "Stuck incoming files" | |
$strMessageBody = $strbody | |
$strSendingServer = "mail.example.com" | |
# Email objects | |
$objSMTPMessage = New-Object System.Net.Mail.MailMessage $strFromAddress, $strToAddress, $strMessageSubject, $strbody | |
$objSMTPClient = New-Object System.Net.Mail.SMTPClient $strSendingServer | |
$objSMTPClient.Send($objSMTPMessage) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment