Joining property sets from two objects

Posted on 2009-02-12
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
    LVL 18

    Accepted Solution

    I think that is best way.

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

    Author Comment

    by:Chris Dent

    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 70

    Author Closing Comment

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


    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
    Set OWA language and time zone in Exchange for individuals, all users or per database.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now