Skip to content

Instantly share code, notes, and snippets.

@pstakuu
Created February 9, 2022 21:18
Show Gist options
  • Select an option

  • Save pstakuu/174de57527405c87031fb6a52d31d791 to your computer and use it in GitHub Desktop.

Select an option

Save pstakuu/174de57527405c87031fb6a52d31d791 to your computer and use it in GitHub Desktop.
Calculated Properties
$exampleData = [PsCustomObject]@{
SimpleField1 = "user"
ComplexField2 = @{
Property1 = "value1"
Property2 = "value2"
}
}
<#
$exampleData
Name Value
---- -----
ComplexField2 {Property1, Property2}
SimpleField1 user
$exampleData.ComplexField2
Name Value
---- -----
Property1 value1
Property2 value2
#>
$exampleData | Select-Object SimpleField1,@{Name = "Property1 of ComplexField"; Expression = {$_.ComplexField2.Property1}},@{N = "N is shorthand for Name"; E = {"E is shorthand for Expression and is a scriptblock"}}
<#
$exampleData | Select-Object SimpleField1,@{Name = "Property1 of ComplexField"; Expression = {$_.ComplexField2.Property1}},@{N = "N is shorthand for Name"; E = {"E is shorthand for Expression and is a scriptblock"}}
SimpleField1 Property1 of ComplexField N is shorthand for Name
------------ ------------------------- -----------------------
user value1 E is shorthand for Expression and is a scriptblock
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment