We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Joining property sets from two objects

Chris Dent
Chris Dent asked
on
Medium Priority
467 Views
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?

Chris
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

Comment
Watch Question

Commented:
I think that is best way.

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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Author

Commented:

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.

Chris
Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Author

Commented:
Thank you, hope you have a good weekend :)

Chris
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.