首页 > 解决方案 > 如何在powershell格式表中显示行号或行号

问题描述

我希望格式表提供的数据包含项目的行号或行号。我怎样才能做到这一点?

一些命令 | 英尺

Line    Something       Else
----    ---------       ----
0       Item1           Property1
1       Item2           Property2

标签: powershell

解决方案


这是我的看法。我的一些 osx 进程没有作为普通用户的名称。

get-process | where name | 
  foreach { $line = 0 } { $line++; $_ } | 
  ft @{n='line';e={$line}}, name, id


line Name              Id
---- ----              --
   1 accountsd        368
   2 AirPlayUIAgent   508
   3 akd             2415
   4 AMPDeviceDiscov  412
   5 AppleSpell      1937

拿两个:

ps | where name | select -first 5 | 
  foreach { $line = 0 } { $_ | add-member -passthru line (++$line) } |
  select line,name,id


line Name              Id
---- ----              --
   1 accountsd        368
   2 AirPlayUIAgent   508
   3 akd             2415
   4 AMPDeviceDiscov  412
   5 AppleSpell      1937

推荐阅读