title: How to pass a variable (array of strings) to other PowerShell scripts
body: <p>I have a variable, $Tasks, in a PowerShell script that contains an array of strings, and I need to pass the variable along to other PowerShell scripts and do stuff with it, like loop through the array and do things with each item (string).</p>
  
  <p>However, at some point along the way my variable gets converted from an array to a string (usually when it hits script2.ps1), and I'm not able to loop through it. What do I need to do to keep the variable as an array throughout the entire process?</p>
  
  <p>Here is the workflow of the variable:</p>
  
  <p><strong>Script1.ps1</strong>:</p>
  
  <pre><code>$Tasks = @(
  "Task1 - Name1",
  "Task2 - Name2",
  "Task3 - Name3"
  )
  
  powershell "&amp; {. $pwd\Script2.ps1 -BuildNum $BuildNum; Run-Validation -Tasks $Tasks}"
  </code></pre>
  
  <p><strong>Script2.ps1</strong>:</p>
  
  <pre><code>param(
      $Tasks=$()
  )
  
  Function Run-Validation
  {
      param($Tasks)
  
      If ($Tasks)
      {
          Test-Tasks $Tasks
      }
  }
  </code></pre>
  
  <p><strong>Script3.ps1</strong>:</p>
  
  <pre><code>Function Test-Tasks ($Tasks)
  {
      ForEach ($Task in $Tasks)
      {
          do_stuff
      }
  }
  </code></pre>