Last active
November 25, 2019 14:18
-
-
Save skunkie/510105ea7bcc2b86d97066dfd70449fe to your computer and use it in GitHub Desktop.
PSObject with op_Addition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class MyPSObject : PSObject { | |
static [MyPSObject] op_Addition ([MyPSObject] $Object1, [MyPSObject] $Object2) { | |
<# | |
$obj1 = [mypsobject] @{a = 1} | |
$obj2 = [mypsobject] @{b = 2; c = 3} | |
$obj3 = [mypsobject] @{c = 0; d = 4} | |
$obj1 + $obj2 + $obj3 | |
a c b d | |
- - - - | |
1 0 2 4 | |
#> | |
$hashTable = [ordered] @{ } | |
foreach ($object in @($Object1, $Object2)) { | |
foreach ($property in $object.PSObject.Properties) { | |
$hashTable[$property.Name] = $property.Value | |
} | |
} | |
return [MyPSObject] $hashTable | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment