1

In powershell, I am trying to add different values into an array. I am grabbing one of the values thats an int from an Array. The rest are string values. I tried + , and add( ) . Is it because they are different values. How can I add different values to an Array?

    #set up values
    $dataIdListNameNonSpecial = @{}
    $email_general = "[email protected]"
    $name_general ="John Smith"
    $numArray = 123 , 222 ,333

    #set up temp array
    $tempArray = $numArray[ 0 ], $email_general,  $name_general

    #try to add into array
    $dataIdListNameNonSpecial += , $tempArray 

    #try to add diffent way into array
    $dataIdListNameNonSpecial.Add( $tempArray)

2 Answers 2

3

@{} creates a hash table, not an array. Use @() instead, and use += to add to the array.

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

Comments

0

Referring to your script, you can add them like this :

$dataIdListNameNonSpecial = @{}
    $email_general = "[email protected]"
    $name_general ="John Smith"
    $numArray = 123 , 222 ,333


    $dataIdListNameNonSpecial.Email_General =$email_general
    $dataIdListNameNonSpecial.Name_general= $name_general
    $dataIdListNameNonSpecial.NumArray= $numArray

$dataIdListNameNonSpecial

Hope It helps you.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.