combine object properties into one object in PowerShell

Question:

I am trying to combine multiple object properties into one object.

When I have the following code the objects properties are combined.

However, if I replace the above computer and osInfo variables with

then the $computer variables does not have the properties of the $osInfo variable after the for loop is executed. ie: the second object is not combined with the first object.

Answer:

The original code deals with cmdlets that returns two single objects relating to the same source.

You’re trying to use it with cmdlets that return arrays of multiple objects.

The following basically merges the two arrays.

Personally, I’d just use the two lines for $services and $processes and be done.

Source:

combine object properties into one object in PowerShell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply