powershell - Powershell - 合并两个 Note 属性
问题描述
如何在 powershell 中将两个 Note 属性合并在一起?
以下查询返回实例列表,但我想合并注释属性,如下所示。
$((Get-Counter '\Process(Chrome*)\ID Process' -ErrorAction SilentlyContinue).CounterSamples | % {[regex]$a = "^.*\($([regex]::Escape($_.InstanceName))(.*)\).*$";[PSCustomObject]@{InstanceName=$_.InstanceName;InstanceId=$a.Matches($($_.Path)).groups[1].value}})
查询的输出是:
InstanceName InstanceId
------------ ----------
Chrome #2
Chrome #1
Chrome
但我希望输出是这样的..
InstanceName
------------
Chrome#2
Chrome#1
Chrome
解决方案
您只需将第一个属性的表达式值更改为:
@{InstanceName="$($_.InstanceName)$($a.Matches($($_.Path)).groups[1].value)"}})
在全:
(Get-Counter '\Process(Chrome*)\ID Process' -ErrorAction SilentlyContinue).CounterSamples | % {[regex]$a = "^.*\($([regex]::Escape($_.InstanceName))(.*)\).*$";[PSCustomObject]@{InstanceName="$($_.InstanceName)$($a.Matches($($_.Path)).groups[1].value)"}}
推荐阅读
- common-lisp - 如何在运行时编译 s-expression,然后在 Common Lisp 中执行
- html - HEAD 内部标签显示在 BODY 标签中
- javascript - 使用 Javascript 在 Google 地图中显示/隐藏标记集群
- java - 在 Javafx 中实现 sql 查询的问题
- c# - 使用单声道时缺少 Microsoft.Extensions.DependencyInjection 的 System.Collection 依赖项
- android - 通过密码进入第二个活动
- c# - 在不同的 UI 线程上创建的 WPF 访问窗口
- entity-framework-core - 如何调试包管理器控制台执行的 ef 核心代码?
- java - Arrays.fill() 和用于初始化链表数组的 for 循环之间的区别
- svn - Adacore GPS 错误消息“无法在路径上找到可执行文件:svn”