PowerTip of the Day-Adding Extra Information

原文地址: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

posted @ 2010-06-17 15:23  哥本哈士奇(aspnetx)  阅读(272)  评论(0编辑  收藏  举报