-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Select-Object Expressions and Aliasing #4160
Copy link
Copy link
Closed
Labels
area-utilityArea - Microsoft.PowerShell.Utility moduleArea - Microsoft.PowerShell.Utility module
Description
This document should include examples on how to evaluate expressions and also how to alias or rename properties that are selected.
- Expressions. You can add the result of an expression to the output of Select-Object by simply adding a { code block } to the list.
For example:
Get-Process | Select ProcessName, { $_.CPU.toString("##") }
- You can alias or rename the property or the result of an expression by using a hash of @{l="PropertyName"; e={ "someExpression" }
For example:
Get-Process | Select @{l="CustomProcName"; e={ $_.ProcessName }}
The special @{l="Label";e={"Expression"}} format is very powerful but I am frustrated that I cannot find it documented here.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: de5b7722-8a95-74e1-0cc3-83ccaaa2db71
- Version Independent ID: b02a39dc-b661-7dac-4482-276ca3724504
- Content: Select-Object (Microsoft.PowerShell.Utility)
- Content Source: reference/6/Microsoft.PowerShell.Utility/Select-Object.md
- Product: powershell
- Technology: powershell-cmdlets
- GitHub Login: @JamesWTruher
- Microsoft Alias: jimtru
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-utilityArea - Microsoft.PowerShell.Utility moduleArea - Microsoft.PowerShell.Utility module