PowerShell v2 Use Format Table with Expressions

Since March 1st Ive been working on some reviews of Don Jones Learn Windows PowerShell in a Month of Lunches.  One of the chapters focused on the Format- cmdlets.  Until I read Dons book I didnt realize the Format- cmdlets worked with expressions in the same way that Select-Object does.  As I worked through the chapter I realized this would pretty helpful.  For instance, in a situation where I would use Select with an expression it does not necessarily allow formatting.  So, instead of using Select I opted for Format-Table so I could use the -Auto to get things to fit more neatly.  In this example, I used Format-Table -Auto with an expression to get the date (MM/dd/yyyy format) and the file name only:
dir | ft @{e={$_.lastwritetime.ToString(MM/dd/yyyy)};l=Date},name -auto | clip
| clip on the end just passes the output to the clipboard so I can paste it later.

Related Posts by Categories

0 comments:

Post a Comment