title: PowerShell: Passing an ArrayList of Objects into another Script as an Argument
body: <p>I am trying to pass an ArrayList that contains objects into another PowerShell script to execute something further.</p>
  <p>The error message that I am receiving is:</p>
  <blockquote>
  <p>&quot;Cannot process argument transformation on parameter 'al'. Cannot convert the &quot;System.Collections.Hashable System.Collections.Hashable System.Collections.Hashable&quot; value of type &quot;System.String&quot; to type &quot;System.Collections.ArrayList&quot;&quot;</p>
  </blockquote>
  <p>In script1.ps1:</p>
  <pre><code>$al = New-Object System.Collections.ArrayList
  
  ...
  
  $obj =  @{&quot;var1&quot;=&quot;apple&quot;; &quot;var2&quot;=&quot;banana&quot;; &quot;var3&quot;=&quot;carrot&quot;;}
  $al.Add($obj)
  
  ...
  
  
  foreach ($i in $al) {
      $temp = $($i.var1)
      write-host &quot;$temp&quot;     #outputs &quot;apple&quot; correctly
  }
  
  invoke-expression -Command &quot;script2.ps1 -al '$al'&quot;
  </code></pre>
  <p>In script2.ps1:</p>
  <pre><code>param ([System.Collections.ArrayList]$al)
  
  ...
  
  foreach ($i in $al) {
      $temp = $($i.var1)
      write-host &quot;$temp&quot;     #error message
  }
  </code></pre>