mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Make Update-1st object props an advanced cmdlet & faster
This commit is contained in:
@@ -5,20 +5,28 @@ param()
|
||||
|
||||
function Update-FirstObjectProperties {
|
||||
[CmdletBinding()]
|
||||
param()
|
||||
try {
|
||||
$Union = @()
|
||||
$Input | ForEach-Object {
|
||||
If ($Union.Count) {
|
||||
$_ | Get-Member | Where-Object {-not ($Union[0] | Get-Member $_.Name)} | ForEach-Object {
|
||||
$Union[0] | Add-Member -MemberType NoteProperty -Name $_.Name -Value $Null
|
||||
}
|
||||
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)
|
||||
}
|
||||
$Union += $_
|
||||
}
|
||||
$Union
|
||||
}
|
||||
catch {
|
||||
throw "Failed updating the properties of the first object: $_"
|
||||
catch {throw "Failed updating the properties of the first object: $_"}
|
||||
}
|
||||
end { $Union }
|
||||
}
|
||||
Reference in New Issue
Block a user