Use Hash Tables for Custom Columns

by Dec 10, 2009

Hash tables can generate "calculated" columns. All you need to do is store two pieces of information: a "label," which serves as new column header, and an "expression," which is the code used to calculate the column:

$age = @{label='Age' expression={ (New-TimeSpan $_.LastWriteTime).Days }}
dir $env:windir | ft name, $age

In the example, $age defines a new column called "Age," which calculates how old files are (in days, using the last modification date).

Twitter This Tip! ReTweet this Tip!