Add New Properties To Your Objects

You can use Select-Object to add new properties to an existing object. In PowerShell v.2, Select-Object accepts a wildcard, which in turn adds all existing properties. Why would that be useful? Have a look:

Dir | Select-Object *, Age |
Foreach-Object { $_.Age=(new-timespan $_.LastWriteTime).Days; $_ } |
Format-Table Name, Age
Dir | Select-Object *, Age |
Foreach-Object { $_.Age=(new-timespan $_.LastWriteTime).Days; $_ } |
Format-Table Name, Age

Twitter This Tip! ReTweet this Tip!


Posted Nov 16 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.