How do I dynamically add elements to arrays in PowerShell?
$testArray = [System.Collections.ArrayList]@()
$tempArray = "123", "321", "453"
foreach($item in $tempArray)
{
$arrayID = $testArray.Add($item)
}
The problem is one of scope; inside your addToArray function change the line to this:
$script:testArray += $Item1
...to store into the array variable you are expecting.