如何循环通过从PowerShell中的csv文件的一行

编程入门 行业动态 更新时间:2024-10-26 22:29:02
本文介绍了如何循环通过从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文件的一行

本文发布于:2023-05-29 15:07:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/347277.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   PowerShell   csv

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!