Created
April 4, 2017 14:57
-
-
Save maldonadojuan/2d9cd789ae9f14cb76ca074277ea7887 to your computer and use it in GitHub Desktop.
This PowerShell script checks that a file has been modified on today's current date and sends an email with success or failure.
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
$filename = "C:\folder\file.TXT" | |
$success = "$filename has been modified today. The file is good." | |
$failure = "!!!ERROR!!! $filename has not been modified today. Server may have not received a file!!!" | |
if (Test-Path $filename) { | |
if ((Get-Item $filename).LastWriteTime -ge (Get-Date).Date) { | |
#Email success to admin | |
$transcript = $success | |
$transcript = $transcript | Out-String | |
$PSEmailServer = "mailrelay.contoso.com" | |
Send-MailMessage -From "IT <it@contoso.com>" -to "John Doe <John.Doe@contoso.com>","Jane Doe <Jane.Doe@contoso.com>" -Subject "Modified File" -Body $transcript | |
} | |
else { | |
#Email success to admin | |
$transcript = $failure | |
$transcript = $transcript | Out-String | |
$PSEmailServer = "mailrelay.contoso.com" | |
Send-MailMessage -From "IT <it@contoso>" -to "John Doe <John.Doe@contoso.com>","Jane Doe <Jane.Doe@contoso.com>" -Subject "Modified File" -Body $transcript | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment