Skip to content

Select-Object hashtable syntax is long-winded, support a shorter version? #8107

@HumanEquivalentUnit

Description

@HumanEquivalentUnit

Select-Object's hashtable syntax - even with abbreviating the key names to one character, it's a lot of code and symbols, and feels like it could be cleaner. The simple case of taking one property value unchanged, but with a new name, could be a lot cleaner.

What if a single-key hashtable could be used, where the key is the new property name, and the value is either a string of the original property to rename, or a scriptblock calculation. e.g.

# property rename, and property calculation, shown in:
# Long form
# Short form - nicer, but not good for scripts because it's using abbreviations
# Suggested form

gci | select @{Label='ShortName'; Expression='BaseName'}, @{name='size'; expression={$_.Length / 1MB}}

gci | select @{L='ShortName'; E={$_.BaseName}}, @{N='size'; E={$_.Length / 1MB}}

gci | select @{ShortName='BaseName'}, @{Size={$_.Length / 1MB}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifIssue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions