【问题标题】:Powershell script to split one column to two columnsPowershell脚本将一列拆分为两列
【发布时间】:2021-05-11 19:51:06
【问题描述】:

我正在尝试在 csv 文件中提取按计数排序的进程报告。

在这里,我在 csv 文件中的单个列中获取输出,如下所示,用空格分隔(显示部分输出)

$process0 = Get-Process
$process1 = $process0.ProcessName
$process1 | 
  Group-Object -NoElement | 
  sort Count -Descending |
  Format-Table |
  Out-File D:\Testing\process.csv

我需要 csv 文件中计数和名称的单独列中的输出 [Count 的第一列和Name 的第二列]。有人可以帮忙吗?

输出:

Count Name                     
----- ----                     
   86 svchost                  
   13 chrome                   
    1 rundll32                 
    1 Registry 

【问题讨论】:

    标签: powershell


    【解决方案1】:

    改变这个

    $process0 = Get-Process 
    $process1 = $process0.ProcessName 
    $process1 | Group-Object -NoElement | sort Count -Descending | Format-Table |  Out-File D:\Testing\process.csv1
    

    到这里

    $process0 = Get-Process
    $process1 = $process0.ProcessName
    $process1 | Group-Object -NoElement | sort Count -Descending | Select-object Name,Count |export-csv D:\Testing\process.csv -notypeinformation
    

    您使用了Format-Table 这将输出转换为屏幕上的文本,而不是管道中具有多个属性的对象。取出Format-Table,然后使用Export-Csv而不是Out-File

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多