Use Hash Tables for Custom Columns

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!


Posted Dec 10 2009, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.