title: How do I concatenate a string within a loop with PowerShell?
body: <p>The command</p>
  
  <pre><code>Get-VM | Where {$_.PowerState -eq "PoweredOn"} | Select Name,VMHost | Where {$_ -match "abc" -or $_ -match "def"} | foreach{$_.Name} | Out-File output.txt
  </code></pre>
  
  <p>writes a list to output.txt where only the column Name will be printed in the form:</p>
  
  <pre><code>a
  b
  c
  ...
  </code></pre>
  
  <p>Now what I want to achieve is to append <code>,xxx</code> to each line in some sort of loop, so that I get the following:</p>
  
  <pre><code>a,xxx
  b,xxx
  c,xxx
  ...
  </code></pre>
  
  <p>I tried to append the string, but this doesn't seem to work:</p>
  
  <pre><code>Get-VM | Where {$_.PowerState -eq "PoweredOn"} | Select Name,VMHost | Where {$_ -match "abc" -or $_ -match "def"} | foreach{$_.Name} | Out-File output.txt | Add-Content output.txt ",xxx"
  </code></pre>
  
  <p>I'm really not familiar with PowerShell, and I did not find a way to concatenate <code>,xxx</code>.</p>
  
  <p><strong>In my case it is essential to do the concatenation within a loop, not with a file operation afterwards.</strong></p>