-
Notifications
You must be signed in to change notification settings - Fork 410
/
Copy pathUpdate-FirstObjectProperties.ps1
32 lines (30 loc) · 1.34 KB
/
Update-FirstObjectProperties.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope='Function', Target='Update*', Justification='Does not change system state')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Scope='Function', Target='Update*', Justification='Property would be incorrect')]
param()
function Update-FirstObjectProperties {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline=$true)]
$InputObject
)
begin { $union = New-Object -TypeName System.Collections.ArrayList }
process {
try {
If ($union.Count -eq 0) {
[void]$union.Add($InputObject)
$memberNames = (Get-Member -InputObject $InputObject -MemberType Properties).Name
}
else {
foreach ($propName in (Get-Member -InputObject $InputObject -MemberType Properties).Name) {
if ($propName -notin $memberNames) {
Add-Member -InputObject $Union[0] -MemberType NoteProperty -Name $propName -Value $Null
$memberNames += $propName
}
}
[void]$Union.Add($InputObject)
}
}
catch {throw "Failed updating the properties of the first object: $_"}
}
end { $Union }
}