Format-Table -Autosize
is great but when used with -GroupBy
, the columns width is computed group by group, not for the whole thing.
My idea was to $tmp = $data | Format-Table -Autosize
$tmp = $data | Format-Table -Autosize
, retrieve the computed columns width from $tmp
, build a hash table describing the columns with their width and then $data | Sort-Object <column> | Format-Table $hash -GroupBy <column>
$data | Sort-Object <column> | Format-Table $hash -GroupBy <column>
But despite many attempts to Google Format-Table
result structure and $tmp | Get-Member
$tmp | Get-Member
I can not find the information I'm looking for.
Do you have any clue?
Have fun digging. It looks like the column widths are in there somewhere:
ps terminal | format-table -autosize | select *
ClassId2e4f51ef21dd47e99d3c952918aff9cd : 033ecb2bc07a4d43b5ef94ed5a35d280
pageHeaderEntry :
pageFooterEntry :
autosizeInfo : Microsoft.PowerShell.Commands.Internal.Format.AutosizeInfo
shapeInfo : Microsoft.PowerShell.Commands.Internal.Format.TableHeaderInfo
groupingEntry :
ClassId2e4f51ef21dd47e99d3c952918aff9cd : 9e210fe47d09416682b841769c78b8a3
shapeInfo :
groupingEntry :
ClassId2e4f51ef21dd47e99d3c952918aff9cd : 27c87ef9bbda4f709f6b4002fa4af63c
formatEntryInfo : Microsoft.PowerShell.Commands.Internal.Format.TableRowEntry
outOfBand : False
writeStream : None
ClassId2e4f51ef21dd47e99d3c952918aff9cd : 4ec4f0187cb04f4cb6973460dfe252df
groupingEntry :
ClassId2e4f51ef21dd47e99d3c952918aff9cd : cf522b78d86c486691226b40aa69e95c
groupingEntry :
$a = ps terminal | format-table -AutoSize
$a | foreach gettype
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
False False FormatStartData Microsoft.PowerShell.Commands.Internal.Format.StartData
False False GroupStartData Microsoft.PowerShell.Commands.Internal.Format.StartData
False False FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.PacketInfoData
False False GroupEndData Microsoft.PowerShell.Commands.Internal.Format.ControlInfoData
False False FormatEndData Microsoft.PowerShell.Commands.Internal.Format.ControlInfoData
Hmm... I appear to have hit a dead end.
$a[0] | select -expand autosizeinfo
out-lineoutput : Unknown class Id a27f094f0eec4d64845801a4c06a32ae.
+ CategoryInfo : InvalidData: (Microsoft.PowerShel\u2026Format.AutosizeInfo:PSObject) [out-lineoutput], PSArgumentException
+ FullyQualifiedErrorId : FormatObjectDeserializerDeserializeInvalidClassId,Microsoft.PowerShell.Commands.OutLineOutputCommand
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.