Functions/array.ps1
function Merge-Array( [object[]]$array = $(), [Parameter(Mandatory = $true)] [object[]]$arrayToMerge, [object[]]$excludeList = $(), [ValidateSet("union", "overwrite")] [string] # array merge type: union, or overwrite. Default is union. $arrayMergeType = 'union' ) { if ($array -ceq $null) { return $arrayToMerge } [string[]]$skipItems = $() foreach ($property in $excludeList) { $skipItems += Get-PropertyName $property } [object[]]$filteredArray = $() foreach ($item in $array | Where-Object {((Get-PropertyName $_) -CNotIn $skipItems )}) { $skipItems += Get-PropertyName $item if ($arrayMergeType -ceq 'union') { $filteredArray += $item } } foreach ($item in ($arrayToMerge | Where-Object {((Get-PropertyName $_) -CNotIn $skipItems )})) { $filteredArray += $item } return $filteredArray } function Convert-ArrayToStringParams([object[]]$list = $()) { $result = '' foreach ($item in $list) { $result += '"{0}" ' -f $item } return $result } |