title: Cycling through multiple variables in for loop
body: <p>I just started working with Powershell and this is my first script.</p>
  
  <p>I am checking for 3 strings in last 50 lines of a log file. I need to find all three strings and print error message if any one of those is missing. I have written following script but it does not give me the expected results.</p>
  
  <pre><code>(Get-Content C:\foo\bar.log )[-1..-50] | Out-File C:\boom\shiva\log.txt
  $PO1 = Get-Content C:\boom\shiva\log.txt | where {$_ -match "&lt;Ping:AD_P01_RCV&gt; ok"}
  $PO2 = Get-Content C:\boom\shiva\log.txt | where {$_ -match "&lt;Ping:AD_P02_SND&gt; ok"}
  $PO3 = Get-Content C:\boom\shiva\log.txt | where {$_ -match "&lt;Ping:AD_P03_RCV&gt; ok"}
  </code></pre>
  
  <p>I am satisfied with above piece of code. The problem is with the below. I dont want to use if-else thrice. I am struggling to draft a for loop which can save space and still give me the same result.</p>
  
  <pre><code>if (!$PO1)
  {
      "PO1 is critical"
  }
  else
  {
      "PO1 is OK"
  }
  if (!$PO2)
  {
      "PO2 is critical"
  }
  else
  {
      "PO2 is OK"
  }
  if (!$PO3)
  {
      "PO3 is critical"
  }
  else
  {
      "PO3 is OK"
  }
  </code></pre>
  
  <p>Can someone gave me small example of how i can fit these 3 if-else in one for loop.</p>