title: Powershell Foreach-Object -Parallel how to change the value of a variable outside the loop (track progress)
body: <p>This code prints a simple progression, doing one thing at a time:</p>
  <pre><code>$files = 1..100
  $i = 0
  $files | Foreach-Object {
      $progress = (&quot;#&quot; * $i)
      Write-Host  &quot;`r$progress&quot; -NoNewLine
      $i ++
      Start-Sleep -s 0.1
  }
  </code></pre>
  <p>But if I want to do two things in parallel at the same time, I can't output the progress because I can't change the variable outside the parallel loops. This doesn't do what's needed:</p>
  <pre><code>$files = 1..100
  $i = 0
  $files | Foreach-Object -ThrottleLimit 2 -Parallel {
      $progress = (&quot;#&quot; * $i)
      Write-Host  &quot;`r$progress&quot; -NoNewLine
      $i ++
      Start-Sleep -s 0.1
  }
  </code></pre>
  <p>I can't find a good solution for accessing an external variable not only to read it with $Using, but also to change it. Is this even possible in Powershell 7?</p>