title: PowerShell copy on write behavior depends on operator type
body: <p>PowerShell uses copy-on-write semantic for inner scopes.</p>
  
  <p>This means that if you'll change outer variable in the inner scope then inner scope would deal with it's own copy. Here is an example:</p>
  
  <pre><code>$list = @(1, 2)
  
  Function Foo
  {
    "Foo: initial value - $list"
    $list = $list + 3
    "Foo: `$list: $list, `$global:list: $global:list"  
  }
  </code></pre>
  
  <p>The output would be:</p>
  
  <pre><code>Foo: initial value - 1 2
  Foo: $list: 1 2 3, $global:list: 1 2
  </code></pre>
  
  <p>Ok, this behavior is by design. But lets change <code>Foo</code> function a bit:</p>
  
  <pre>Function Foo
  {
    "Foo: initial value - $list"
    <b><i>$list += 3</i></b>
    "Foo: `$list: $list, `$global:list: $global:list"  
  }</pre>
  
  <p>The output would be:</p>
  
  <pre>Foo: initial value - 1 2
  Foo: $list: <b><i>3</i></b>, $global:list: 1 2</pre>
  
  <p>Hm... I can assume that <code>x += y</code> operator is not exactly the same that <code>x = x + y</code>. But that is not exacted. Let's change the code once more:</p>
  
  <pre>Function Foo
  {
    <b><i>New-Variable -Name z -Value 42</i></b>
    "Foo: initial value - $list"
    $list += 3
    "Foo: `$list: $list, `$global:list: $global:list"  
  }</pre>
  
  <p>And now the output would be:</p>
  
  <pre><code>Foo: initial value - 1 2
  Foo: $list: 1 2 3, $global:list: 1 2
  </code></pre>
  
  <p>It seems like a bug. The only question is where exactly? I assume behavior of <code>+=</code> in second case is incorrect. But maybe I missing something...</p>