Formatting Output

<Pipeline> | <Formatting Command>

When objects reach the end of the output pipeline, PowerShell converts them to text to make them suitable for human consumption. PowerShell supports several options to help you control this formatting process:

PowerShell formatting commands

Formatting Command

Result

Format-Table <Property List>

Formats the properties of the input objects as a table, including only the object properties you specify. If you do not specify a property list, PowerShell picks a default set.

In addition to supplying object properties, you may also provide advanced formatting statements:

PS > Get-Process | `
   Format-Table -Auto Name,`
   @{Label="HexId";
     Expression={ "{0:x}" -f $_.Id}
     Width=4
     Align="Right"

}

The advanced formatting statement is a hashtable with the keys, Label and Expression (or any short form of them.) The value of the expression key should be a script block that returns a result for the current object (represented by the $_ variable.)

For more information about the Format-Table cmdlet, type Get-Help Format-Table

Format-List <Property List>

Formats the properties of the input objects as a list, including only the object properties you specify. If you do not specify a property list, PowerShell picks a default set.

The Format-List cmdlet supports the advanced formatting statements as used by the Format-Table cmdlet.

The Format-List cmdlet is the one you will use most often to get a detailed summary of an object’s properties.

The command, Format-List * returns all properties, but does not include those that PowerShell hides by default. The command, Format-List * -force returns all properties.

For more information about the Format-List cmdlet, type Get-Help Format-List

Format-Wide <Property>

Formats the properties of the input objects in an extremely terse summary view. If you do not specify a property, PowerShell picks a default set.

In addition to supplying object properties, you may also provide advanced formatting statements:

PS >Get-Process | `
   Format-Wide -Auto `
   @{ Expression={ "{0:x}" -f $_.Id} }

The advanced formatting statement is a hashtable with the key Expression (or any short form of it.) The value of the expression key should be a script block that returns a result for the current object (represented by the $_ variable.)

For more information about the Format-Wide cmdlet, type Get-Help Format-Wide

Custom formatting files

All of the formatting defaults in PowerShell (e.g., when you do not specify a formatting command, or when you do not specify formatting properties) are driven by the *.Format.Ps1Xml files in the installation directory in a manner very similar to the type extension files mentioned in the “Custom type extension files” segment of the section “Working with the .NET Framework.”

To create your own formatting customizations, use these files as a source of examples, but do not modify them directly. Instead, create a new file and use the Update-FormatData cmdlet to load your customizations. The following command loads Format.custom.ps1xml from the same directory as your profile:

$formatFile = join-path (split-path $profile) “Format.Custom.Ps1Xml"Update-FormatData –PrependPath $typesFile

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.209.95