PowerShell 技能连载 - Adding New Incrementing Number Column in a Grid View Window

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}}, * |
  Out-GridView

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.

PowerShell 技能连载 - Adding New Incrementing Number Column in a Grid View Window

http://blog.vichamp.com/2018/10/11/adding-new-incrementing-number-column-in-a-grid-view-window/

作者

吴波

发布于

2018-10-11

更新于

2022-07-06

许可协议

评论