本文介绍了如何循环通过从PowerShell中的csv文件的一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在powershell中处理csv文件,但我不知道处理CSV文件中的列标题。
I want to process a csv file in powershell, but I don't know what the column headings in the CSV file will be when it is processed.
例如:
$path = "d:\scratch\export.csv" $csv = Import-csv -path $path foreach($line in $csv) { foreach ($head in $line | get-member | where-object {$_.MemberType -eq "NoteProperty"} | select Definition) { #pseudocode... doSomething($head.columnName, $head.value) } }我循环通过csv文件中的行,获取列的名称和值?或者还有另一种方法,我应该这样做(像不使用Import-csv)?
How do I loop through the line in the csv file, getting the name of the column and the value? Or is there another way I should be doing this (like not using Import-csv)?
推荐答案Import-Csv $path | Foreach-Object { foreach ($property in $_.PSObject.Properties) { doSomething $property.Name, $property.Value } }
更多推荐
如何循环通过从PowerShell中的csv文件的一行
发布评论