0

I have a custom object where I have added properties of a variable to it directly but there is one property with holds multiple values . How do I add all those multiple values to my custom object ?

This works fine if there is one-one value

 $info | Add-Member -Type NoteProperty -Name "USEDSPACE %" -Value $usage

but in this case $result.name isnt working , where $result.name has a set of values not one

$info | Add-Member -Type NoteProperty -Name PATHS -Value $result.name
Fenomatik
  • 457
  • 2
  • 8
  • 22
  • 3
    What do you mean by *isnt working*? How result different from what you want? – user4003407 Feb 19 '16 at 22:53
  • @PetSerAl its working when I try to send it out as HTML it doesnt show up , so I am assuming its not adding and showing this :System.Object[] – Fenomatik Feb 19 '16 at 22:58
  • How do you convert object to HTML? – user4003407 Feb 19 '16 at 23:06
  • Your issue is not with the custom object property having multiple values, it is that when you try to convert to HTML it expects the properties to have strings for values. You will need to convert the array to a string before converting to HTML. `$info | Add-Member 'Paths' ($result.name -join "\`r\`n")` – TheMadTechnician Feb 19 '16 at 23:44

1 Answers1

0

This is how I managed to add multiple values to a PS custom object, maybe you can adapt it to your needs:

$table = New-Object psobject

$table | gm

$keys = New-Object System.Collections.ArrayList

for([int32]$i = 1;$i -le 8;$i++){[void]$keys.add($i)}

$table | Add-Member -MemberType NoteProperty -Name Keys -Value $keys

check your data and type:

$table | gm

$table

$table.Keys

$table.Keys[0]

$table.Keys[5]

You can use of course any data type you need, in my case an int32 was needed, but you can add anything to your list, and the noteproperty of your custom object will have the same data type.

If you want to use the values in your object, you can access them like this, and do something with them.

foreach($key in $table.Keys){[math]::Pow(2,$key)}

Hope I could help!

Syden
  • 8,425
  • 5
  • 26
  • 45
Csaba
  • 1
  • 2