首页 > 解决方案 > 在 PowerShell 输出中插入分隔符

问题描述

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

2623 255336448 178.125 10080 explorer 

为了将此数据摄取到第三方系统中,我需要像这样对结果进行管道分隔:

2623|255336448|178.125|10080|explorer 

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

标签: powershell

解决方案


怎么样:

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

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


推荐阅读