Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the -view parameter of Format-List?

Tags:

powershell

Format-List apparently has a string parameter named "view", as can be seen here. What does it do, and how does it work? I cannot find any documentation beyond "The name of an alternate format or 'view.'"

like image 321
jpmc26 Avatar asked Nov 17 '25 21:11

jpmc26


1 Answers

The '-View' parameter on the various Format-* cmdlets allows you to get various different "views" or formattings of the data e.g.:

PS> Get-Process

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
    672      56   272684     220692   975   141.45   8480 powershell
    692      34    47184      60156   234    23.73  17048 powershell
    751      82   217624     162780  1047   157.73  13336 powershell_ise

versus

PS> Get-Process | Format-Table -View StartTime


   StartTime.ToShortDateString(): 1/14/2013

ProcessName                  Id   HandleCount   WorkingSet
-----------                  --   -----------   ----------
powershell                 8480           672    225988608


   StartTime.ToShortDateString(): 2/6/2013

ProcessName                  Id   HandleCount   WorkingSet
-----------                  --   -----------   ----------
powershell                17048           624     92418048


   StartTime.ToShortDateString(): 1/17/2013

ProcessName                  Id   HandleCount   WorkingSet
-----------                  --   -----------   ----------
powershell_ise            13336           771    166686720

As for determining which commands support alternate views, you can usually find such info in the docs. Here's an excerpt from the Get-Process help:

You can also use the built-in alternate views of the processes available with Format-Table, such as "StartTime" and "Priority", and you can design your own views. For more information, see T:Microsoft.PowerShell.Commands.Format-Table.

The PowerShell Community Extensions also includes a command called Get-ViewDefinition that can get this info when the docs aren't available (or of much help in this regards.

like image 88
Keith Hill Avatar answered Nov 19 '25 13:11

Keith Hill