如何从导入的CSV中提取特定列的数据

时间:2014-11-04 21:18:46

标签: powershell csv

我有这个CSV文件:

Time of Day Process Name    PID Operation   Path    Result
52:24.3 notepad.exe 4828    Process Start       SUCCESS
52:24.3 notepad.exe 4828    Thread Create       SUCCESS
52:24.3 notepad.exe 4828    Load Image  C:\Windows\System32\notepad.exe SUCCESS

我将文件导入变量:

$csvContent = Import-CSV D:\Logfile.CSV

我试图从列" PID":

中提取数据
$csvContent[0] | select PID

但它没有用。
enter image description here

如何将PID列中的数据提取到变量?

1 个答案:

答案 0 :(得分:2)

该CSV文件中没有逗号,并且它将所有标题导入为单个标题的标题。

您需要为文件中的元素指定/指定分隔符。

例如:

Time of Day,Process Name,PID,Operation,Path,Result
52:24.3,notepad.exe,4828,Process Start,,SUCCESS
52:24.3,notepad.exe,4828,Thread Create,,SUCCESS
52:24.3,notepad.exe,4828,Load Image,C:\Windows\System32\notepad.exe,SUCCESS