Functions/object.ps1
function Merge-Object( [Parameter(Mandatory = $true)] [object]$base, [Parameter(Mandatory = $true)] [object]$addition, [ValidateSet("union", "overwrite")] [string] # array merge type: union, or overwrite. Default is union. $arrayMergeType = 'union' ) { $baseItem = ($base).PsObject.Copy() $addition.psobject.Properties | ForEach-Object { $value = $_.Value if ($arrayMergeType -ceq 'union' -and $_.TypeNameOfValue -ceq "System.Object[]") { $defaultValue = $baseItem | select -ExpandProperty $_.Name -ErrorAction SilentlyContinue $value = Merge-Array $defaultValue $_.Value } $baseItem | Add-Member -MemberType $_.MemberType -Name $_.Name -Value $value -Force } return $baseItem } |