1

I have an array or PSCustomObject called: $results = @()

I have a nested hash table called: $allResults = @{}

$results |ft, shows this in console:

Brokering        Name             WriteCacheSize   dFreeSpace   (and more...)   
---------        ----             --------------   ----------            
N/A              server0001       0,004            22,83             
N/A              server0002       0,004            21,86           

$allresults |ft shows this:

Name                       Value                                                
----                       ----
server0001                     {SCOMStatus, PVSServer, RegistrationState, ServerLoad...}
server0001                     {SCOMStatus, PVSServer, RegistrationState, ServerLoad...}                     

The name is in common in both $. There should be a way to add the values in $results to $allresults, but I don't know how to do it.

I want everything in the hash nested table. How can I add the values in the $results to the $allresults. The goal is having a nested table with every value.

C. Helling
  • 1,394
  • 6
  • 20
  • 34
Jose
  • 11
  • 1
  • 2
  • Do you mean the `$allResults` hash table contains values that are your custom objects? – Bill_Stewart Jul 07 '17 at 14:28
  • I do not have access to the actual objects to test it, but try: [`$results, $allresults | Union | ft`](https://stackoverflow.com/questions/44428189/not-all-properties-displayed/44429084#44429084) – iRon Jul 07 '17 at 14:44
  • Or try: [$results, $allresults | Merge-Hashtables | ft](https://stackoverflow.com/questions/8800375/merging-hashtables-in-powershell-how/32890418#32890418) – iRon Jul 07 '17 at 14:59
  • To convert a PSObject to a hash table (or visa versa), see: https://stackoverflow.com/a/3740403/1701026 – iRon Jul 07 '17 at 15:32

2 Answers2

0

If you're trying to add the values of an array to a hashtable you can loop through the array and use $allresults.Add(<key>,<value>).

Jason Snell
  • 1,425
  • 12
  • 22
0

Thanks everybody for their responses. I finally achieved to do it. I created another object with custom properties, and then I fullfilled the hash table. This is the code:

$myObjectProperties = @(
"Brokering"
"PVSServer"
"Name"
"VDA"
"WMI"
"vDisk"
"dFreeSpace"
"WriteCacheSize"
"Spooler"
"CitrixPrint"
"Uptime"
"cFreeSpace"
"RunspaceId"
)
foreach ($element in $results){
    foreach ($property in $myObjectProperties){
        $allresults.$($element.Name).$property = $element.$property
    }
}
Jose
  • 11
  • 1
  • 2