Using Calculated Columns in New Objects

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!


Posted Dec 11 2009, 08:00 AM by ps1

Comments

Twitter Trackbacks for Using Calculated Columns in New Objects - Power Tips - PowerShell.com [powershell.com] on Topsy.com wrote Twitter Trackbacks for Using Calculated Columns in New Objects - Power Tips - PowerShell.com [powershell.com] on Topsy.com
on 12-11-2009 10:32 AM

Pingback from  Twitter Trackbacks for                 Using Calculated Columns in New Objects - Power Tips - PowerShell.com         [powershell.com]        on Topsy.com

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.