title: How to read a line from a file in PowerShell
body: <p>I am novice to the PowerShell scripting. I am looking to fulfill one of my requirement.</p>
  
  <p>I have one <a href="http://en.wikipedia.org/wiki/Hosts_(file)" rel="nofollow noreferrer">hosts file</a> which is having multiple host names and IP addresses. Below is the example of the input file.</p>
  
  <pre><code>127.0.0.1 Host1 Host2 Host3
  
  127.0.0.2 Host4 Host5 Host6
  </code></pre>
  
  <p>I want to read each line and ping for the first host (Host1), then the second host (Host2) and then the third host (Host3).</p>
  
  <p>While pinging each host name, I need to check the ping response IP address for that host and match it back with the IP address mentioned in the input file. Below is the snippet of code with which am trying to read the file in the above format, but it is not working in that way.</p>
  
  <pre><code> $lines = Get-Content myfile.txt
      $lines |
       ForEach-Object{
           Test-Connection  $_.Split(' ')[1]
       }
  </code></pre>
  
  <p>Can anyone give me any advice or whip something in a PowerShell script for me?</p>