Reputation: 23
I know I am missing something small. But, I am overlooking something. I want the script to look in a specific path for the newest log file, and check the last line of the log file, and if it contains a specific error, have it email a notification. It finds the newest file properly, but doesn't seem to be giving me the output of the last line. Thoughts on what silly thing I missed?
Set-Location -Path "\\COMPUTER\C$\application\logs"
$latest = Get-ChildItem | Sort-Object LastAccessTime -Descending | Select-Object -First 1
$latest.name
$lastentry = Get-Content $latest | Select-object -last 1
if ($lastentry -like "ERROR: Access violation at address*") {
$strFromAddress = "[email protected]"
$strToAddress = "[email protected]"
$strMessageSubject = "Your log has errors"
$strMessageBody = "Bad stuff is happening"
$strSendingServer = "mail.acertaindomain.com"
}
Upvotes: 0
Views: 2695
Reputation: 23
I'm such an idiot. I thank you guys for the input. All those email tags and I completely forgot the actual command to send the bloody email.
I just brain farted in the worst way. But also, your added logic helped proof it. I of course realized I was jacking up something silly when write-output displayed what I was looking for.
Remember kids, it's all great to set variables. But don't forget to do something with them. lol
Upvotes: 1