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 @   哥本哈士奇(aspnetx)  阅读(274)  评论(0编辑  收藏  举报
编辑推荐:
· 理解Rust引用及其生命周期标识(下)
· 从二进制到误差:逐行拆解C语言浮点运算中的4008175468544之谜
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
阅读排行:
· 2025成都.NET开发者Connect圆满结束
· 后端思维之高并发处理方案
· 千万级大表的优化技巧
· 在 VS Code 中,一键安装 MCP Server!
· 10年+ .NET Coder 心语 ── 继承的思维:从思维模式到架构设计的深度解析
历史上的今天:
2007-06-17 盖茨来华演讲视频下载地址
2007-06-17 Microsoft acquires DUNDAS technology for SQL SERVER 2008
点击右上角即可分享
微信分享提示