Understanding Formatting
Formatting Strategy
- Looks for pre-defined formatting specification(View) in
*.format.ps1xmlfiles. - Follow instruction like
Format-Table. - Direct
ToStringfor- primitive types in .NET
- objects without any public property
NOTE
Since PowerShell 6.0, pre-defined formatting specification are presented in C# source code. You can still load your own specification by ps1xml files.
NOTE
To formatting
Format as Table
- Format by
-Propertywith specific property names or calculated property
ps1
gps | ft -Property Name,ID # pick two columns
gps | ft @{ n = 'CMD'; e = 'Name' } # create custom column by calculated property1
2
2
- Toggle headers by
-HideTableHeaders - Format with custom View by
-View - Group by property
-GroupBy - Enable word wrap by
-Wrap -RepeatHeaderto make sure each page has a header for certain pager likeless,moreandOut-Host -Paging
ps1
# display groups separately
gci -file | ft -GroupBy Extension1
2
2