title: Working with a var outside Foreach-Object
body: <p>I have this code which works as it should:</p>
  
  <pre><code>Get-Content $path\$newName -Encoding OEM |ForEach-Object {$_ -replace '&lt;Num:(\d{8,20})&gt;$','$1'}| Set-Content $path\$txtName -Encoding UTF8
  </code></pre>
  
  <p>The string is replaced by the digits. But I would like to be able to use $1 outside the loop.</p>
  
  <p>Like:</p>
  
  <pre><code>write-host $1
  </code></pre>
  
  <p>For example. But if i do this noting is output.
  Any suggestions?</p>
  
  <p>Thanks.</p>