title: If Else Statement with String, Exporting to CSV
body: <p>I am a powershell newbie and was creating a small script to import a list of Laptops and Workstations from a text file, pinging them to see if they are on our network and continuing to check the computer's agent status/config.</p>
  
  <p>If the computer isn't online, I would like to have an out files saying $workstation is not online.</p>
  
  <p>The Issue I had is getting that failure string to one CSV with the other data, I can export IF and Else separately, however it would be nice to have it on one CSV if possible.</p>
  
  <p>Any thoughts? Thanks!</p>
  
  <pre><code>$workstation=Get-content C:\Scripts\workstation.txt
  
  $forloop=ForEach ($workstation in $workstation) {
  
         if (Test-Connection -ComputerName $workstation -Count 1 -Quiet) {Get-Service -ComputerName $workstation | where-object {$_.Name -eq 'xxx Agent'} | select displayname, name, starttype, status |
          export-csv -Path C:\Scripts\therealdeal.c }
  
         Else {Write-Output "$workstation not available Out"}
         }
  
  $forloop | Out-File C:\scripts\output.csv 
  </code></pre>