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[2] = "Value1"
$Arr[6] = "Value6"
# And append more elements in chunks if I need
$Arr += 1..10
for more info:
get-help about_array
~Clint
"Frank" <Frank@discussions.microsoft.com> wrote in message
news:104CD347-3D9A-4546-BC64-4A41E9702912@microsoft.com...
> Hi,
>
> I need to assign values to an array, but they may not be in order. ie,
>
> $ar[0] = "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
> specific
> element.
>
> 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,
>
> Frank
>
>