Author Posts

July 29, 2017 at 11:38 pm

I've been searching, but not finding a solution that's working

    $Props01 = [ordered]@{
        'Prop01A' = 'Prop01A_Value'
        'Prop01B' = 'Prop01B_Value'
    } #end $Props01
    $Obj01 = New-Object -TypeName PSObject -Property $Props01

    $Props02 = [ordered]@{
        'Prop02A' = 'Prop02A_Value'
    } #end $Props02
    $Obj02 = New-Object -TypeName PSObject -Property $Props02

Obj01 contains:
Prop01A
Prop01B

Obj02 contains
Prop02A

I'd like to be able to make Obj03 which contains:
Prop01A
Prop01B
Prop02A

I know I can mix/match and place all three in a single hashtable, but I'm looking at having dozens of these custom objects "groups" and want to be able to pick and choose which Obj0x gets merged with Obj0y.

$Props03 = [ordered]@{
'Prop01A' = 'Prop01A_Value'
'Prop01B' = 'Prop01B_Value'
'Prop02A' = 'Prop02A_Value'
}

Thanks.

July 29, 2017 at 11:55 pm

Yeah, there's not a "merge." That really goes against the original concepts of object-oriented programming, which is why; objects aren't simply "data structures," although in PowerShell we admittedly use them that way a lot. The most you could probably do is write a Merge-Object command which programmatically does this for you.

July 30, 2017 at 12:37 am

Thank you for that explanation. I kept searching after my post, and this link provides the solution I was looking for.

http://powershelldistrict.com/how-to-combine-powershell-objects/ (See post by David, 3/8/2017).