This little script I used when I was having a problem with my TV Tuner card on my home server. Every now and then it would stop working and it was a real pain to come home and find that the shows I had set to tape hadn't recorded because the card stopped working. So this script would email me to let me know that it was time to perform some percussive maintenance on my usb tv tuner card again.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
#Set the log file that you would like to check. $log = get-content -Path "\\<server>\For The Record\Logs\ForTheRecord.RecorderTuner.log" #Set the current date in the desired format. $currdate = get-date -uformat %Y-%m-%d # Set a variable to use as the script loops through each line of the log file. $cantconnect = $true ForEach ($line in $log){ if($cantconnect ){ #This Variable splits the line of the log by the space. $currline = $line -split ' ' , 2 #This variable takes the first part of the $currline array. $linedate = $currline[ 0] #Set the erroractionpreference to silently continue so that the script will keep going through even if it errors. (Not best practice, I know...:() $erroractionpreference = "SilentlyContinue" #This next line checks for a match only for todays date. (I had this running as a schedule task every day.) $match = "$currdate " -match "$linedate " if($match ){ #If it finds a match of the date, it will then search for this string via a switch statement. If it finds a match it breaks out of the loop and sets the $ #$cantconnect variable to $false. switch -wildcard ($currline[ 1]){"*Card AF9015 BDA Filter returned Card error : Fatal*" {$cantconnect = $false; break} default {$cantconnect = $true} } } } else { #If it finds an error it will then email. $EmailFrom = "<email address="" from="">" $EmailTo = "<email address="" to="">" $Subject = "ForTheRecord Down" $Body = "Fix tuner card. Something wrong with one of the cards. Investigate." $SMTPServer = "<smtp server="">" $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer , 25) $SMTPClient.Send( $EmailFrom, $EmailTo, $Subject, $Body) break } } |