Skip to content
ConsoleMonster
Cmdlet

New-ConsoleKeyValue

Module
ConsoleMonster
Inputs
System.Object
Outputs
ConsoleMonster.Widgets.KeyValueList

Creates an aligned key/value list from a hashtable, an object's properties or Key/Value records pairs.

Syntax

New-ConsoleKeyValue
[-Columns <Int32>]
[[-Content] <ScriptBlock>]
[-Gap <Int32>]
[[-InputObject] <Object>]
[-KeyRole <ThemeToken>]
[-Markup]
[-MaxKeyFraction <Double>]
[-NumberColumn <ColumnFormat>]
[-Presentation <PresentationOptions>]
[[-WidgetId] <String>]
[<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

Pairs come from a hashtable (use [ordered] to keep order), from an object's properties, or from a script block of Key/Value records calls when a pair needs a status marker, markup or a presenter. Keys are muted and aligned; values wrap. Values are shown literally unless -Markup is used. In a live dashboard, update pairs with Update-Console.

Examples

Example 1

New-ConsoleKeyValue -InputObject ([ordered] @{ Domain = 'evotec.xyz'; Records = 14; DNSSEC = 'not signed' }) | Show-Console

A summary block

Example 2

New-ConsoleKeyValue -Content {
    [pscustomobject]@{ Key = 'Version'; Value = '0.0.4 [muted]→[/] [bold]2.0.0[/]'; Markup = $true }
    [pscustomobject]@{ Key = 'Signing'; Value = 'skipped'; Status = 'Skip' }
    [pscustomobject]@{ Key = 'Tests'; Value = '1 skipped on PowerShell 7'; Status = 'Warn' }
} | Show-Console

Pairs with status marks

Example 3

$keyValueOptions = @{
    InputObject = ([ordered] @{ Module = 'ConsoleMonster'; Frameworks = 'net472, net8.0' })
    Content = {
        [pscustomobject]@{ Key = 'Signing'; Value = 'skipped'; Status = 'Skip' }
    }
}
New-ConsoleKeyValue @keyValueOptions | Show-Console

A hashtable and pairs together

Example 4

Get-ConsoleDemo -Slug 'build-steps' | Select-Object -ExpandProperty Source
Get-ConsoleDemo -Slug 'scheduled-tasks' | Select-Object -ExpandProperty Source

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

Parameters

-Columns Int32 optional
Preferred pairs per row; reduces automatically in narrow terminals.
-Content ScriptBlock optionalposition: 2
A script block that emits Key/Value records pairs (or hashtables), added after -InputObject.
-Gap Int32 optional
Cells between the key column and values.
-InputObject Object optionalposition: 1pipeline: True (ByValue)
A hashtable or an object whose properties become the pairs. A record containing both Key and Value is an item descriptor, even when Value is null; Key by itself is ordinary data. A script block here is taken as -Content.
-KeyRole ThemeToken optional
Theme role for keys.
Possible values: Text, Muted, Subtle, Accent, Accent2, Pass, Fail, Warn, Info, Skip, Running, Pending, Border, Title, Header, Highlight, Surface, SurfaceAccent, Series1, Series2, Series3, Series4, Series5, Series6, Focus, Strong, Low, Critical, Gap
-Markup SwitchParameter optional
Treat values as markup.
-MaxKeyFraction Double optional
Preferred key fraction when natural widths do not fit.
-NumberColumn ColumnFormat optional
Shared NumberColumn layout settings as a hashtable, for example @{ MinWidth = 6; Alignment = 'Right' }.
-Presentation PresentationOptions optional
Shared value-formatting culture, clock and time zone.
-WidgetId String optionalposition: 0
The live name used by Update-Console (default keyvalue).

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.