New-ConsoleKeyValue
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>]#All Parameter SetsDescription
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-ConsoleA 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-ConsolePairs 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-ConsoleA hashtable and pairs together
Example 4
Get-ConsoleDemo -Slug 'build-steps' | Select-Object -ExpandProperty Source
Get-ConsoleDemo -Slug 'scheduled-tasks' | Select-Object -ExpandProperty SourceRead 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
- Preferred pairs per row; reduces automatically in narrow terminals.
- -Content ScriptBlock
- A script block that emits Key/Value records pairs (or hashtables), added after -InputObject.
- -Gap Int32
- Cells between the key column and values.
- -InputObject Object
- 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
- 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
- Treat values as markup.
- -MaxKeyFraction Double
- Preferred key fraction when natural widths do not fit.
- -NumberColumn ColumnFormat
- Shared NumberColumn layout settings as a hashtable, for example @{ MinWidth = 6; Alignment = 'Right' }.
- -Presentation PresentationOptions
- Shared value-formatting culture, clock and time zone.
- -WidgetId String
- 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.