1

For some reason PowerShell takes an array of strings and converts it into a single string (or perhaps a character array?) when it is set as the second dimension of a two dimensional array:

Here is the initial output of the $path array:

PS C:\Users\crd> $path
C:
Program Files (x86)
Common Files
Adobe
ARM
1.0
armsvc.exe

The path[0] array entry is a string value:

PS C:\Users\crd> $path[0]
C:

Now we set the first value in the $test[] array equal to our string array:

PS C:\Users\crd> $test[0]=$path

You can see that the entire string array has been merged:

PS C:\Users\crd> $test[0]
C: Program Files (x86) Common Files Adobe ARM 1.0 armsvc.exe

Why is this? I'm sure Microsoft documented this somewhere but I'm having a hard time finding it.

I would expect the output to remain unchanged. Note the following output:

PS C:\Users\chris> $test[0][0]
C

I would like this to be the same as the $path[0] output which was C:. Why is this merge occurring?

15
  • What would you expect it to set it to? Commented Jun 14, 2016 at 14:42
  • @Sean Revised my question a bit - hope that helps. Commented Jun 14, 2016 at 14:51
  • 1
    Where does $path come from? What type is it? Why do you want to work with multi dimensional arrays? Commented Jun 14, 2016 at 15:09
  • 1
    What it $test, how is this different from the question you asked yesterday and why do you keep wanting to re-appropriate and reuse the same variables? :) Commented Jun 14, 2016 at 15:20
  • Why not use a hashtable or a powershell object and store the path a string then split it when you need to process? Commented Jun 14, 2016 at 15:20

1 Answer 1

0

you changed your hash of items into a single string value. works as expected.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.