Reputation: 860
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)
Upvotes: 1
Views: 334
Reputation: 62542
@{}
creates a hash table, not an array. Use @()
instead, and use +=
to add to the array.
Upvotes: 3
Reputation: 9351
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.
Upvotes: 0