Skip to content

Instantly share code, notes, and snippets.

@scriptingstudio
Last active March 17, 2025 18:19
Show Gist options
  • Select an option

  • Save scriptingstudio/04e1cf491b92954c6cc4bc45c83eb557 to your computer and use it in GitHub Desktop.

Select an option

Save scriptingstudio/04e1cf491b92954c6cc4bc45c83eb557 to your computer and use it in GitHub Desktop.
Yet another fast way to extend/align objects in the object collection
function Align-Object {
$property = [ordered]@{}
$collection = @($input)
foreach ($obj in $collection) {foreach ($p in $obj.psobject.properties.name) {$property[$p] = 1}}
$collection | Select-Object -property @($property.keys -ne 'Length')
}
function Align-Object1 {
$property = [System.Collections.Generic.HashSet[string]]::new()
$collection = @($input)
foreach ($obj in $collection) {foreach ($p in $obj.psobject.properties.name) {$null = $property.Add($p)}}
$collection | Select-Object -property @($property -ne 'Length')
}
[pscustomobject] @{ one = 1; two = 2; three = 3 },
[pscustomobject] @{ six = 133; seven = 2; three = 3 },
[pscustomobject] @{ one = 10; three = 30; four = 4 } |
Align-Object | ft
one two three six seven four
--- --- ----- --- ----- ----
1 2 3
3 133 2
10 30 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment