-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Select-Object hashtable syntax is long-winded, support a shorter version? #8107
Copy link
Copy link
Closed
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe 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 bugthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Description
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}}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe 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 bugthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module