Skip to content
ConsoleMonster

PowerShell conventions

One grammar for every widget: containers take script blocks, items are commands with shared parameters, and .NET methods still work.

Every widget is a New-Console* command, and they read the same way, so a widget you have not used yet works like the last one.

  • Containers take a script block of children. New-ConsoleRows, New-ConsoleColumns, New-ConsoleGrid, New-ConsolePanel, New-ConsoleStack, New-ConsoleAlign, New-ConsolePadding and New-ConsoleRegion lay out what their script block emits; strings are markup text.
  • Widgets with items take a script block of item commands, with the same parameter names everywhere: New-ConsoleTreeNode for New-ConsoleTree, New-ConsoleKeyValueItem for New-ConsoleKeyValue, New-ConsoleStatusItem for New-ConsoleStatusList and New-ConsolePhases, New-ConsoleBarItem for New-ConsoleBarChart, New-ConsoleChartSeries for New-ConsoleLineChart, New-ConsoleLogEntry for New-ConsoleLog and New-ConsoleLane for New-ConsoleLanes. Items can also come from the pipeline, and simple data still works with -Data hashtables and -Value arrays.
  • Hierarchical objects become a tree. New-ConsoleTree follows children with -ChildrenProperty or a -Children script block and keeps a large or cyclic hierarchy bounded with -Depth, -MaxItems and -MaxNodes.
  • A widget made earlier grows with Add-ConsoleItem, which takes the same item commands; a widget in a running dashboard changes through the live commands (Update-ConsoleStatus, Write-ConsoleLog, Add-ConsoleValue...).
New-ConsoleTree '[bold]evotec.xyz[/]' {
    New-ConsoleTreeNode 'MX' -Status Pass -Detail '2 records' {
        New-ConsoleTreeNode 'evotec-xyz.mail.protection.outlook.com' -Detail 'priority 0'
    }
    New-ConsoleTreeNode 'SPF' -Status Warn -Detail '9 of 10 DNS lookups'
    New-ConsoleTreeNode 'DMARC' -Status Fail -Detail 'p=none'
} | Write-ConsoleWidget

$groups | New-ConsoleTree 'Privileged groups' -ChildrenProperty Members -StatusProperty Health -Depth 3 | Write-ConsoleWidget

Shared parameters

ParameterMeaning everywhere
-StatusPass, Fail, Warn, Skip, Info, Running, Pending, plus PowerShell's words (Success, Warning, Error, Failed, Skipped...), with tab completion.
-LevelLog levels: Information, Warning, Error, Verbose, Debug, Success, or info, warn, err.
-DetailA muted note beside the label: a duration, a count, a short reason.
-ToneA colour as a theme role: Accent, Pass, Fail, Warn, Muted, Series1 to Series6.
-Value and -PresenterWhat an item shows, and how: Bytes, Duration, Date, Number, Boolean...
-MarkupOpt-in markup for data values; titles and labels take markup without it.
-AtA time: a TimeSpan, seconds, or 500ms, 2s, 1.5m, 1h.

Every widget, both ways

The cmdlet form is what the documentation shows first. Each widget is also an ordinary .NET object, so a script can keep it in a variable and call its methods, the way C# code does.

WidgetCmdlet formGrow it laterIn a dashboard.NET methods
TreeNew-ConsoleTree + New-ConsoleTreeNodeAdd-ConsoleItemAdd(label, status, note) returns the node
Key/value listNew-ConsoleKeyValue + New-ConsoleKeyValueItemAdd-ConsoleItemSet-ConsoleValueAdd(key, value, status), AddValue(key, value, presenter)
Status listNew-ConsoleStatusList + New-ConsoleStatusItemAdd-ConsoleItemUpdate-ConsoleStatusAdd(label, status, detail)
PhasesNew-ConsolePhases + New-ConsoleStatusItemAdd-ConsoleItemUpdate-ConsolePhaseSet(key, status, label, detail)
Bar chart, stacked barNew-ConsoleBarChart + New-ConsoleBarItemAdd-ConsoleItemAdd-ConsoleValue, Set-ConsoleValueAdd(label, value, token)
Line and scatter chartNew-ConsoleLineChart + New-ConsoleChartSeriesAdd-ConsoleItemAdd-ConsoleValue -KeyAddSeries(name, token), Add(series, value)
Sparkline, histogramNew-ConsoleSparkline, New-ConsoleHistogramAdd-ConsoleItemAdd-ConsoleValueAdd(value)
LogNew-ConsoleLog + New-ConsoleLogEntryAdd-ConsoleItemWrite-ConsoleLogWrite(text, level, time)
LanesNew-ConsoleLanes + New-ConsoleLaneAdd-ConsoleItemUpdate-ConsoleLaneAdd(key, label, total) returns the lane
Progress, spinnerNew-ConsoleProgress, New-ConsoleSpinnerUpdate-ConsoleProgress, Update-ConsoleSpinnerValue, Status, Detail
Live tableNew-ConsoleLiveTableAdd-ConsoleItemUpdate-ConsoleTableSet(key, values), Remove(key)
Cell map, summary barNew-ConsoleCellMap, New-ConsoleSummaryBarAdd-ConsoleItem (cell map)drawn by Invoke-ConsoleRunAdd(state), SetProgress, SetCounter
RegionNew-ConsoleRegionSet-ConsoleRegionsession.Region(name).Set(widget)

The same log written both ways:

New-ConsoleLog -Height 5 {
    New-ConsoleLogEntry 'Discovered 4 domain controllers in 2 domains' -Level Info -At 2s
    New-ConsoleLogEntry 'DC02: USN rollback check failed (event 2095)' -Level Error -At 44s
} | Write-ConsoleWidget
# Using the object directly
$log = New-ConsoleLog -Height 5
$log.Write('Discovered 4 domain controllers in 2 domains', 'info', [timespan]::FromSeconds(2))
$log.Write('DC02: USN rollback check failed (event 2095)', 'err', [timespan]::FromSeconds(44))
$log | Write-ConsoleWidget

The full conventions, with every widget and parameter, are in Docs/PowerShell-Conventions.md, and every command is in the command reference.

Edit this page on GitHub