powershell - 在 PowerShell 输出中插入定界符

标签 powershell

Get-Process -Name explorer 的结果 |选择 Handles,WS,CPU,Id,ProcessName | ft -HideTableHeaders 返回以下输出:

2623 255336448 178.125 10080 explorer 

为了将这些数据提取到第三方系统中,我需要用管道分隔结果:

2623|255336448|178.125|10080|explorer 

实现此目标的最佳方法是什么?

最佳答案

怎么样:

(Get-Process explorer |
  Select-Object Handles,Ws,CPU,ID,ProcessName |
  ConvertTo-Csv -Delimiter '|' -NoTypeInformation |
  Select-Object -Skip 1) -replace '"',''

仅使用 ft (Format-Table) 以便在 PowerShell 控制台中轻松查看(这不利于将数据发送到其他应用程序,因为那样您将不得不撤消格式化 - 所以一开始就不要格式化)。

关于powershell - 在 PowerShell 输出中插入定界符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50535720/

相关文章:

powershell - 在 Powershell 中工作时,如何在列表项之间暂停?

arrays - 将 JSON 数组索引列值转置为行并导出为 CSV

windows - Powershell Windows 应用程序获取发布者显示名称

Azure Pipelines - 使用 PowerShell 将变量值插入到 JSON 中

powershell - 为什么使用 .Invoke() 调用 Powershell 脚本 block 会返回一个集合?

powershell - 具有约束的Powershell随机获取

Powershell 是否有一种简单的方法可以将 int 5 转换为字符串 5 或 68 转换为 68?

powershell - DSC 资源中是否可以有可选的 Key 属性?

Powershell根本无法连接到互联网

powershell - 从命令行将 pfx 文件导入到特定的证书存储中