Out-default can convert an object to visual text. In fact, Out-default will call Format-table first, and more properties will be hidden by default. Then call Out-host to output the result to the console. So the following three sets of command execution results are the same.
ls
ls | format-table | Out-host
ls | Out-default
Show hidden Object Properties
To view all properties of the object's results, use the
ls | Format-table *
This allows you to use text wrapping parameters because there are too many properties and properties that may not appear completely
ls | Format-table *-wrap
Format pipe Results
First, use the following command to view all commands that begin with format
PS c:powershell> get-command-verb format
commandtype Name Definition
----------- ---- ----------
Cmdlet format-custom format-custom [[-property]
cmdlet format-list format-list [[- Property]
cmdlet format-table format-table [[-property]
cmdlet format-wide Format-wide [[-property]
Format-custom: Use a custom view to format the output.
Format-list: Formats the output as a list of properties, each of which is displayed in one row.
Format-table: Formats the output as a table.
Format-wide: Sets the object's format to a wide table that can display only one property of each object.
Displays the specified properties
To display the specified property, you first need to know the name of the property in the result object, for example:
PS c:powershell> ls | Format-table name,length,lastwritetime
Name Length lastwritetime
---- ------ ---------- ---
ABC 2011/11/23 17:25:53
myscript 2011/11/29 18:21:28 a.html 67580 2011/11/ 18:30:13
a.txt 26384 2011/11/24 20:04:31
alias 12060 2011/11/24 20:26:36
Using wildcard characters
For example, to see the current process with I, and show the name of the process and other processes that start with "PE" and End With "64″."
PS c:powershell> get-process i* | Format-table name,pe*64
Name peakpagedmemorysize PeakWorkingSet64 peakvirtualmemorysi Ze64
---- ------------------- -----------------------------------
Idle 0 0 0
imecfmui 946176 4292608 48054272
imecmnt 1564672 5320704 65482752
imedictupdate 1224704 4579328 31965184
Script Block as a property
The length of the file in PowerShell is default to byte if you want it to output in kilobytes, consider the following method of envy.
PS c:powershell> ls | format-table name,{[int] ($_. LENGTH/1KB)}
Name [int] ($_. LENGTH/1KB)
---- ----------------------
function.ps1
logotestconfig.xml 0
ls.html 3
name.html 7
Modify column headings
Using a composite property, if you use a script block as a caption, it's very unpleasant to see. You can use the lable setting. The same is the case above, slightly modified.
PS c:powershell> $column = @{expression={[int] ($_. LENGTH/1KB)}; Label= "KB"}
PS c:powershell> Dir | Format-table name, $column
name KB
---- ----------------------
function.ps1
Logotestconfig.xml 0
ls.html 3
name.html
Optimize column width
Because most of the output of PowerShell is a real-time streaming pattern, the next result is unknown, and PowerShell results are distributed by default, so that the width of the console can be maximized, but the bandwidth of the column can be optimized by-auto parameters. Compares the maximum bandwidth of a property value to the width of each column:
PS c:powershell> ls
directory: C:powershell
Mode lastwritetime Length Name
---- ------------- ----------
d---- 2011/11/23 17:25 ABC
d---- 2011/11/29 18:21 MyScript-a
--- 2011/11/24 18:30 67580 a.html-a
--- 2011/11/24 20:04 26384 a.txt
PS c:powershell> ls | Format-table-autosize
directory: C:powershell
Mode lastwritetime Length Name
---- ------------- ----------
D----2011/11/23 17:25 ABC
d----2011/11/29 18:21 myscript
-a--- 2011/11/24 18:30 67580 a.html