Skip to content

Instantly share code, notes, and snippets.

@skunkie
Last active November 25, 2019 14:18
Show Gist options
  • Save skunkie/510105ea7bcc2b86d97066dfd70449fe to your computer and use it in GitHub Desktop.
Save skunkie/510105ea7bcc2b86d97066dfd70449fe to your computer and use it in GitHub Desktop.
PSObject with op_Addition
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