title: Powershell: Get return result from Powershell Script called from Within other PS Script
body: <p><strong>Background:</strong>
  I have a powershell script:<code>script1</code> that takes in a <code>sourceDirectory</code> and two destinations (call them <code>dest1Directory</code> and <code>dest2Directory</code>).</p>
  
  <p>The sourceDirectory is structured like this:</p>
  
  <blockquote>
    <p>\Source\dest1\STUFF1</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>\Source\dest2\STUFF2</p>
  </blockquote>
  
  <p><code>script1</code> calls another script:<code>script2</code>, <code>foreach</code> STUFF (so <code>script2</code> may be run 10 times for example), providing <code>script2</code> with the necessary destination parameter, which creates backups of all of the contents "STUFF" is replacing on <code>dest1Directory</code> and <code>dest2Directory</code>, and then copies all of STUFF to the corresponding destination.</p>
  
  <p><code>Script1</code>:</p>
  
  <pre><code>foreach ($folder in $STUFF1)
  {           
  &amp; $script2 -stuffParameter $folder -destDrive $dest1Directory -backUpDrive $BackUpDirectory
  }
  </code></pre>
  
  <p><strong>The issue I'm having is:</strong></p>
  
  <p>I'm calling <code>script1</code> from a visual studio website and would like <code>script2</code> to output all of the backup directory paths it creates so I have references to them for later. I have tried this inside of <code>script2</code>:</p>
  
  <pre><code>$returnRollBackObj = New-Object Object
  Add-Member -memberType NoteProperty -name "RollBackLocation" -value $folderobj -inputObject $returnRollBackObj
  return $returnRollBackObj
  </code></pre>
  
  <p>But it doesn't seem to return the objects since they are subscript calls. I don't know how to return an undefined number of these objects from <code>script1</code> so I'm at a loss. Can someone help me out?</p>