Skip to content
ConsoleMonster
Cmdlet

New-ConsoleTable

Module
ConsoleMonster
Inputs
System.Management.Automation.PSObject[]
Outputs
ConsoleMonster.Widgets.Table ConsoleMonster.Interactive.AppBinding

Creates a console table from pipeline objects.

Syntax

New-ConsoleTable
[-Border <Rounded|Square|Double|Minimal|Rule>]
[-Caption <Object>]
[-CardsBelow <Int32>]
[-Expand]
[-GroupBy <Object>]
[[-InputObject] <PSObject[]>]
[-MaxRows <Int32>]
[-NoHeaderSeparator]
[-NoSort]
[-Property <Object[]>]
[-ShowGroupColumn]
[-ShowTotals]
[-StatusProperty <String>]
[-Title <Object>]
[-Wrap]
[<CommonParameters>]
#
Parameter set: Objects
New-ConsoleTable
[-Border <Rounded|Square|Double|Minimal|Rule>]
[-Caption <Object>]
[-CardsBelow <Int32>]
[-Descending]
[-Expand]
[-Filter <String>]
[-GroupBy <Object>]
[[-InputObject] <PSObject[]>]
[-KeyProperty <String>]
-Live
[-MaxRows <Int32>]
[-NoHeaderSeparator]
[-NoSort]
[-Property <Object[]>]
[-ShowGroupColumn]
[-ShowTotals]
[-SortColumn <Object>]
[-StatusProperty <String>]
[-Table <Table>]
[-Title <Object>]
[[-WidgetId] <String>]
[-Wrap]
[<CommonParameters>]
#
Parameter set: Live
New-ConsoleTable
-Bind <ScriptBlock>
[-Border <Rounded|Square|Double|Minimal|Rule>]
[-Caption <Object>]
[-CardsBelow <Int32>]
[-Expand]
[-GroupBy <Object>]
[-MaxRows <Int32>]
[-NoHeaderSeparator]
[-NoSort]
[-Property <Object[]>]
[-ShowGroupColumn]
[-ShowTotals]
[-StatusProperty <String>]
[-Title <Object>]
[-Wrap]
[<CommonParameters>]
#
Parameter set: Bind

Description

Columns come from -Property or from the first object's properties (or hashtable keys). Property descriptors accept presenter names or configured C# ICellPresenter instances. Columns size to their content, numbers are right-aligned, long values wrap. A -StatusProperty column shows status markers (pass, fail, warn...) as the row's one colour signal.

Examples

Example 1

$tableOptions = @{
    Property = @('Name', 'Status', 'Region')
    StatusProperty = 'Status'
    Title = 'Servers'
}
@(
    [pscustomobject]@{ Name = 'web01'; Status = 'Pass'; Region = 'East' }
    [pscustomobject]@{ Name = 'web02'; Status = 'Warn'; Region = 'West' }
) | New-ConsoleTable @tableOptions | Show-Console

Build a table widget from two server records and display it. Property orders the columns. StatusProperty maps the values in Status to markers. A dashboard or layout can consume the same widget in its Content block.

Example 2

$items = @(
    [pscustomobject]@{ Name = 'web01'; Status = 'Pass' }
    [pscustomobject]@{ Name = 'web02'; Status = 'Warn' }
)
Show-ConsoleApp -Content {
    New-ConsoleTextInput -Key Query
    $tableOptions = @{
        Bind = { $items | Where-Object Name -Like "*$($State.Query)*" }
        Property = @('Name', 'Status')
        StatusProperty = 'Status'
    }
    New-ConsoleTable @tableOptions
}

Filter rows as the app's Query field changes. New-ConsoleTextInput writes to the state key named Query. The Bind script block reads that key from the current $State hashtable and emits matching records, which the table turns into rows. Start with an empty query to see both rows, then type web02.

Example 3

Get-ConsoleDemo -Slug 'server-estate' | Select-Object -ExpandProperty Source
Get-ConsoleDemo -Slug 'live-filter' | Select-Object -ExpandProperty Source

Read any of these gallery scripts to see New-ConsoleTable in a complete example. Each lookup returns the script's source. Use the same slug with Show-ConsoleDemo to run it.

Parameters

-Border TableBorder optional
Border: Rounded, Square, Double, Minimal or None.
Possible values: Rounded, Square, Double, Minimal, Rule
-Caption Object optional
A muted caption below the table.
-CardsBelow Int32 optional
Uses cards below this width; zero keeps a grid.
-Expand SwitchParameter optional
Fill the available width. The text columns share the spare width in proportion to their widths, while number, date and status columns keep their natural width; a column hashtable's Weight (or Flexible) decides the share instead, and Width or MaxWidth holds.
-GroupBy Object optional
Groups rows by a property or script block.
-InputObject PSObject[] optionalposition: 0pipeline: True (ByValue)sets: Objects, Live
The objects to show, one row each.
-MaxRows Int32 optional
For Live, keeps this many recent rows; zero keeps all.
-NoHeaderSeparator SwitchParameter optional
Underline the header instead of drawing a separator row under it.
-NoSort SwitchParameter optional
Keeps groups in input order.
-Property Object[] optional
Properties to show, in order.
-ShowGroupColumn SwitchParameter optional
Keeps the grouping property in the table columns.
-ShowTotals SwitchParameter optional
Adds totals for numeric columns.
-StatusProperty String optional
A property whose values are statuses (pass/fail/warn/skip/running).
-Title Object optional
A title above the table.
-Wrap SwitchParameter optional
Wraps long cell values without limiting their line count.
-Descending SwitchParameter optionalsets: Live
For Live, sorts larger values first.
-Filter String optionalsets: Live
Only displays rows whose cell values match every literal word before formatting, ignoring case. The live table retains hidden rows.
-KeyProperty String optionalsets: Live
For Live, the input property used as the stable row key; omitted uses the first column.
-Live SwitchParameter requiredsets: Live
Creates a keyed live table using the same column and row configuration.
-SortColumn Object optionalsets: Live
For Live, the column index or header used for sorting.
-Table Table optionalsets: Live
For Live, a table model supplying columns and presentation options.
-WidgetId String optionalposition: 0sets: Live
The live widget identifier; default table.
-Bind ScriptBlock requiredsets: Bind
Application-dependent object producer. Receives param($State) and injected $State as a native hashtable on the owning input thread. Emit objects, not widgets; columns and formatting use the same builder as ordinary tables.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.