Maybe you’d like to add a column with incrementing indices to your objects. Try this:

$startcount = 0
Get-Service |
  Select-Object -Property @{N='ID#';E={$script:startcount++;$startcount}}, * |

When you run this chunk of code, you get a list of services in a grid view window, and the first column “ID#” is added with incrementing ID numbers.

The technique can be used to add arbitrary columns. Simply use a hash table with key N[ame] for the column name, and key E[xpression] with the script block that generates the column content.

Twitter This Tip! ReTweet this Tip!