title: How to reference parent in PowerShell script property
body: <p>Given a nested PowerShell custom object like this:</p>
  
  <pre><code>$O = [PSCustomObject]@{ 
   ParentValue = 100
   ChildValueArray = @(
     [PSCustomObject]@{ Name = 'First';  Value = 1 },
     [PSCustomObject]@{ Name = 'Second'; Value = 2 }
  
   )}
  </code></pre>
  
  <p>I would like to add a script property to each of the objects in "ChildArray" that references the value "ParentValue" in the enclosing object.  Conceptually I would like to do the following:</p>
  
  <pre><code>$O.ChildValueArray |  Add-Member -MemberType ScriptProperty -Name Diff -Value { $this.Value + $parent.ParentValue }
  </code></pre>
  
  <p>However there is no $parent equivalent to $this that I can find.</p>
  
  <p>Is there a way to achieve this behaviour so that the result of:</p>
  
  <pre><code>$O.ChildValueArray | Format-Table -AutoSize
  </code></pre>
  
  <p>Is:</p>
  
  <pre><code>Name   Value Diff
  ----   ----- ----
  First      1    101
  Second     2    102
  </code></pre>
  
  <p>Instead of the current value:</p>
  
  <pre><code>Name   Value Diff
  ----   ----- ----
  First      1    1
  Second     2    2
  </code></pre>
  
  <p>I suspect this is not possible for reasons outlined here:</p>
  
  <p><a href="https://stackoverflow.com/questions/6843923/how-to-reference-parent-in-inline-creation-of-objects">How to reference parent in inline creation of objects?</a></p>