Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Joining property sets from two objects

Posted on 2009-02-12
Medium Priority
Last Modified: 2012-05-06

Anyone happen to know if there's a neat way to combine the property sets of two different objects?

I ended up with this to add the properties of one to another since I couldn't find anything immediately obvious. Is there something better?

function Join-Object ($BaseObject, $AdditionalObject) {
  ForEach ($Property in $($AdditionalObject | Get-Member -Type Property)) {
    $BaseObject | Add-Member -MemberType NoteProperty -Name $Property.Name `
      -Value $AdditionalObject.$($Property.Name) -ErrorAction SilentlyContinue
  return $BaseObject

Open in new window

Question by:Chris Dent
  • 2
LVL 18

Accepted Solution

BSonPosh earned 2000 total points
ID: 23625305
I think that is best way.

You could perhaps use Select-Object, but your way is the cleanest that I can think of.
LVL 71

Author Comment

by:Chris Dent
ID: 23636749

Cool, thank you, I'll stick with that one then

The prospect of writing 40 @{n=...;e=...} statements to end up with the combined set was about as unappealing as trimming the property set to a few that may or may not be interesting.

LVL 71

Author Closing Comment

by:Chris Dent
ID: 31546176
Thank you, hope you have a good weekend :)


Featured Post

Who's Defending Your Organization from Threats?

Protecting against advanced threats requires an IT dream team – a well-oiled machine of people and solutions working together to defend your organization. Download our resource kit today to learn more about the tools you need to build you IT Dream Team!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question