You can create an array like this:
$varArray = "Value1","Value2","Value3","Value4","Value5"
and append values as you noted:
$varArray += "Value6"
I don't think you can just randomly assign a value to an arbitrary element.
Changing an arbitrary element is easy though. So what I have done in the
past is something like this:
# Create the array with however many elements I think I might need:
$Arr = 1..20
# Now I can modify any of the elements (0-19, not 1-20)
$Arr = "Value1"
$Arr = "Value6"
# And append more elements in chunks if I need
$Arr += 1..10
for more info:
"Frank" <Frank@discussions.microsoft.com> wrote in message
> I need to assign values to an array, but they may not be in order. ie,
> $ar = "test"
> but I get the error:
> Array assignment failed because index '0' was out of range.
> At line:1 char:5
> + $ar[0 <<<< ] = "test"
> I can add them in sequence, via: $ar += "test" but I cannot add via
> Also, is there a way to create an array via a variable name, ie:
> $var1 = "testname"
> $(`$var1`) = @()
> The goal is to create an array $testname.
> Thanks in advance,