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/