原文地址:http://app.en25.com/e/es.aspx?s=1403&e=4479&elq=5c2d3cdc5fc74ac49db66a5047abbcca

原文:

Sometimes you may want to tag results returned by a cmdlet with some extra information, such as  a reference to some PC name or a timestamp. You can use Add-Member to tag a note property to the result.

This line gets all services and adds two new columns: the PC name, and the date and time the results were returned:

$result = Get-Service | Add-Member NoteProperty Computer $env:computername -pass | Add-Member NoteProperty Timestamp (Get-Date) -pass

$result | Select-Object Status, Name, Computer, Time*


Note that you will only see the new columns if you explicitly ask Select-Object to show them.

 

翻译:

有时需要在cmdlet命令的返回结果中加一些附加的信息,比如机器名或者时间戳。可以在返回的结果中使用Add-Member来标记一个笔记属性。

下面的命令返回所有的服务并且加了附加的两个列:机器名和时间戳:

$result = Get-Service | Add-Member NoteProperty Computer $env:computername -pass | Add-Member NoteProperty Timestamp (Get-Date) -pass

$result | Select-Object Status, Name, Computer, Time*

如果只想显示这两个新增列的话只要通过Select-Object明确指定就可以了。

 

笔记:

Add-Member NoteProperty 列名 -pass

相关文章:

  • 2022-01-21
  • 2021-09-22
  • 2021-10-11
  • 2021-09-26
  • 2021-08-19
  • 2021-11-18
  • 2021-07-15
  • 2021-07-12
猜你喜欢
  • 2022-02-02
  • 2021-12-12
  • 2022-01-16
  • 2021-07-08
  • 2022-02-22
  • 2021-12-03
  • 2022-02-09
相关资源
相似解决方案