Sean's Personal Code Samples And References

Format output as a table.

      Format-Table [[-property] Object[]] [-autosize] [-hideTableHeaders]
          [-groupBy Object] [-wrap] [-view string] [-force]
             [-inputObject psobject] [-expand string]
                [-displayError] [-showError] [CommonParameters]

   -property Object[]
       The object properties to display (in order)
       Wildcards are permitted.
       You cannot use -Property and -View in the same command.

       Adjust the column sizes based on the width of the data.
       Ignore any column details in the view.
       Omit column headings from the table.

   -view string
       The name of an alternate format or "view." 
   -groupBy Object
       Format the output in groups based on a shared property or value.
       Display text that exceeds the column width on the next line. 
       By default, text that exceeds the column width is truncated.

       Directs the cmdlet to display all of the error information.
       Use with -DisplayError or -ShowError. 
       By default, when an error object is written to the error or display streams,
       only some of the error information is displayed.

   -inputObject psobject
       The objects to format. 
       A variable, command or expression that gets the objects.
   -expand string
       Where string is either "EnumOnly" (the default), "CoreOnly" or "Both"
       "CoreOnly" will format and display properties of the collection object itself, 
       while "emumOnly" will enumerate and display the object properties. 
       (designed around the ICollection (System.Collections) interface.)

       Display errors at the command line.

       Send errors through the pipeline.

       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer -OutVariable.
The value of -GroupBy or -Property can be a new calculated property. To create a calculated property, use a hash table. Valid keys are:

Name (or Label) string
Expression string or script block
FormatString string
Width int32    -Property only 
Alignment      -Property only ("Left", "Center", or "Right")

In addition to simply formatting output as a table, Format-Table can be used to add calculated properties to an object before displaying it.

To add calculated properties, use the Property parameter to specify a hash table. The hash table must include two keys: Label and Expression. The Label key is assigned the name of the calculated property. The Expression key is assigned a script block that is evaluated to determine the value of the property.

Custom display formats can also be defined using XML tags see get-help about_Display.xml for details.


Print information about Windows PowerShell snap-ins in a table:

PS C:\>get-pssnapin | format-table -wrap

Print a list of running processes formatted into groups with the same base priority class:

PS C:\>get-process | format-table -groupby basepriority

Print the winlogon process, including a calculated total running time:

PS C:\>get-process winlogon | format-table ProcessName, @{Label="DD.HH:MM:Seconds"; Expression={(get-date) - $_.StartTime}}

Changing the above for the notepad process, notice that this this will add up the running time for ALL notepad processes currently running:

PS C:\>get-process notepad | format-table ProcessName, `
       @{Label="DD.HH:MM:Seconds"; Expression={(get-date) - $_.StartTime}}

Sean Marcellus
There are 10 kinds of people e in this world, those who understand binary and those who don’t.