Send email when numeber is greater than

I am trying to write a script that will look at a log file. There is a line in the file called TOTAL_TIME= . I would like to send an email if TOTAL_TIME is greater than 50000
Below is a sample of what the file looks like.


What do you need in the email body? Is ‘Total_time’ on multiple lines in a log file? How many log files do you need to parse?

I would like the body to say that the search time is at “TOTAL_TIME”
The Total time is only on one line in the text file, I only need to do this on one log file.


get-content c:\temp\logfile.log | ? {$_ -match 'total_time='} | % {
	$totaltime = $_.split('=')[-1]
	$somenumber = 50000
	if ($totaltime -gt $somenumber) {
		#send-mailmessage ...

For some reason the logic will only work up to 9999 If I try 50000 it seem to work… Is this limited to 4 digits? Here is my script. If I change the gt 50000 to 5000 it works. The value in the log file is TOTAL_TIME=7640

Get-Content ‘c:\test\’ |? {$_ -match ‘total_time=’} | % {
$totaltime = $_.split(’=’)[-1]
if ($totaltime -gt50000)
Send-MailMessage -From test-Subject “Searches are above 50000” -To test -Body “test” -SmtpServer
Write-host “Not above 50000”

Cast your totaltime variable as an integer and your code should work.

Get-Content '.\logfile' | ForEach-Object {
    [void]($_ -match 'TOTAL_TIME=.*')
    $time = ($Matches[0] -split '=')[-1]
    If ([int]$time -gt 9999){Send-MailMessage}

Thanks. It works like a charm!!