Count the lines a text file and email if it more than 1000 lines


I wrote a query which will get an output to text file. Below is the query:

psexec \servername netstat -aon | findstr toe >> \servernam1\c$\temp\output\a1.log

Now, I need to count the lines in the log file, if it more than 1000 lines email. I tried few options, but could not achieve email part. Below is the script:


read -r num < a1.txt
if [[ “$num” -gt 1000 ]]; then
echo “Take action!”
echo “All OK!”


Can some help me out at this?

I thought this was a PowerShell forum lol

I wrote a bit powershell command
Get-Content \servernam1\c$\temp\output\a1.log | Measure-Object –Line | Out-File \servernam1\c$\temp\output\a2.log

a2.log contains more than 1000 lines. Now, I need to get an email if it is equal or grater than 1000 lines.

I would suggest the following:

$Lines = (Get-Content \\servernam1\c$\temp\output\a1.log | Measure-Object –Line).Lines
if ($Lines -ge 1000) {
    # email code goes here

You can just use Count, Get-Content is an array of lines:

@(Get-Content -Path C:\Scripts\file1.txt).Count

Look at Send-MailMessage to send an email.