I am trying to pass an ArrayList that contains objects into another PowerShell script to execute something further.
The error message that I am receiving is:
"Cannot process argument transformation on parameter 'al'. Cannot convert the "System.Collections.Hashable System.Collections.Hashable System.Collections.Hashable" value of type "System.String" to type "System.Collections.ArrayList""
In script1.ps1:
$al = New-Object System.Collections.ArrayList
...
$obj = @{"var1"="apple"; "var2"="banana"; "var3"="carrot";}
$al.Add($obj)
...
foreach ($i in $al) {
$temp = $($i.var1)
write-host "$temp" #outputs "apple" correctly
}
invoke-expression -Command "script2.ps1 -al '$al'"
In script2.ps1:
param ([System.Collections.ArrayList]$al)
...
foreach ($i in $al) {
$temp = $($i.var1)
write-host "$temp" #error message
}
Export/Import-CliXmlcmdlets handle PoSh data types very neatly. so i would export to a CliXml file & then have the other script import that file. that way all you need to pass is the full file name. [grin]