Quantcast
Channel: Apttech's Blog
Viewing all articles
Browse latest Browse all 77

Some PowerShell commands or cmdlets – Part 6 – Formatting Output

$
0
0

Getting the column headings of a list of processes:
Get-Process | Select -First 2

72114_1 get-process showing 2 records to view headers

The first two entries are listed and all headers are displayed on the top.

Using the Pipeline operator to format the output
Posh cmdlet used to format the output:

1. Format-table

If you want, you can get a customized list of only two headers:

Get-Process | Format-Table name, id
72114_1 format-table name and id
Notice that the output is screenwide (Posh uses the lenght of the screen to fit all the headers, in this case only 2, so the space between the two headers is wide)
However, you can use the Autosize parameter to widen the column to fit the longest record name, instead of using the default screenwide view:

Get-Process | Format-Table name, id -AutoSize | more

72114_1 format-table name and id using auto-size

So, in this case “AppleMobileDeviceService” is the record with the longest width so the column length get autosized accordingly, in order to fit the longest record;

Get-Process | Format-Table name, id -GroupBy name -AutoSize

2. Format-List

Get-Process | where { $_.pm -gt 20mb } | Format-List * | more

This will list all processes using more than 20mb of memory; The ” * ” will show all items for this process
Get-Service | where { $_.status -EQ “running” } | format-List *

Get-Process | Format-List *Format-Wide

3. Format-Wide
Get-Process | Format-Wide name

Get-Process | Format-Wide name -Column 6

 

 

72114_1 get-process  format-wide name -column 6

Note that all processes are listed in 6 columns; the default number of columns is 2 (two)

Get-Process | Format-Wide name -Auto-Size



Viewing all articles
Browse latest Browse all 77

Trending Articles