$d = import-csv # the original CSV file has 3 properties Prop1,Prop2 and Prop3
$d | Add-member -Membertype Scriptproperty -Name "AddProp4" -Value xxx
Foreach -process {
[pscustomobject]@{ Prop1=$_.Prop1; Prop2=$_.Prop2; Prop3=$_.Prop3; Prop4 = $_.AddProp4 }
} | Sort {$_.Prop4} | Out-gridview
As can be seen, the 3 original propertied are just repeated into the new, “expanded” object. Is there a shorter way to “repeat” the same old properties without having to retype them one by one?
Using Select-Object generates a new PSObject. Using a calculated expression you can generate a static value for all rows or run pretty much any code as well