Using Calculated Columns in New Objects

by Dec 11, 2009

Select-Object can add new properties to objects and fill them with calculated content. All you need for this is a hash table with two pieces of information: "Name" (which is the new property name) and "expression" (which is the code used to calculate the property content).

$age = @{Name='Age' expression={ (New-TimeSpan $_.LastWriteTime).Days }}
dir $env:windir |
Select-Object name, $age |
Export-CSV c:\test.csv

Twitter This Tip! ReTweet this Tip!