Skip to content

Select-Object Expressions and Aliasing #4160

@brandonkirsch

Description

@brandonkirsch

This document should include examples on how to evaluate expressions and also how to alias or rename properties that are selected.

  1. 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("##") }

  1. 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.

Metadata

Metadata

Assignees

Labels

area-utilityArea - Microsoft.PowerShell.Utility module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions