title: Difference between ForEach and ForEach-Object in powershell
body: <p>Is there any difference between <code>ForEach</code> and <code>ForEach-Object</code> ?</p>
  
  <p>I have a small code like this, works fine</p>
  
  <pre><code>$txt = Get-Content 'C:\temp\000.txt'
  $result = foreach ($line in $txt) {$line.replace(".ini","")}
  $result | out-file 'c:\temp\001.txt'
  </code></pre>
  
  <p>But if i use 'ForEach-Object', I got errors....</p>
  
  <pre><code>$txt = Get-Content 'C:\temp\000.txt'
  $result = foreach-object ($line in $txt) {$line.replace(".ini","")}
  $result | out-file 'c:\temp\001.txt'
  </code></pre>
  
  <p>Why ? and how to output the loop results by using <code>ForEach-Object</code></p>