Output Formatting / Filtering
Format
Table
-Wrap
Format Process list with Virtual and Paged Memory in MBs and no Decimals
Understand the "Name" is a property from Get-Process, but also a property for Format-Table. See next example if that doesn't make sense.
Formatting Process List to Include Select Fields:
List
Format-List is another way of displaying the properties of an object. Unlike get-member, Format-List (fl) will also display the values for those properties so that you can see what kind of information each property contains
Most parameters are the same as Format-Table.
gci | Format-List -property name
Formatting output of a command (Format-List)
ls | Format-List -property name
Formatting output of a command (Format-List)
Get-Help Format-List
Formats the help output as a list
Wide
It’s able to display only the values of a single property, so its -Property parameter accepts only one property name, not a list, and it can’t accept wildcards.
Formats the output to a specified width and writes to a new file.
GroupBy
Paging
Paginating output:
Select-Object
Select-Object
or Select
Selects a specified property from an object.
Get-Process | Select Name,ID,CPU,PM
Selects multiple properties.
Get-Process | Select -First 10
Selects first 10.
Get-Process | Select -Last 10
Selects last 10.
Displays the Get-Process Properties of 'Name, ID, Path' for every process
Where-Object
Where-Object
Filters objects out of the pipeline.
Get-Content C:\path\to\file.txt | Where-Object {$_ -match "pattern"}
Filters lines that match a specific pattern.
Get-Process | Where-Object {$_.name -eq "notepad"}
Where-Object condition (alias where or ?).
Creating Custom Columns and List Entries
You can use this to provide a column header that’s different from the property name being displayed:
This creates a special hash table to create a custom column that will be labeled VM(MB) and changes the value of that property to MBs. It then converst that value to a whole number rather than a decimal.
NOTE: PowerShell recognizes the shortcuts KB, MB, GB, TB, and PB as denoting kilobyte, megabyte, gigabyte, terabyte, and petabyte, respectively
Format custom number of columns. Need to use Format-Wide
:
Format list that contains specific fields with one custom field:
Format custom headers for Get-Module's Name and Version:
Last updated
Was this helpful?