Powershell Import-CSV how to skip until particular line based on string?

淺唱寂寞╮ 提交于 2020-01-11 13:15:28

问题


Hi My CSV file is like this

#BEGINPROPERTIES
total.candidate.create=2
duration=0:00:00.433
internal.audit.session.id=1397055568
internal.cluster.node.info=(product:enterprise,id:node796599_796601,http:"10.111.233.79:19788",jgroups:"chprapk11406-44186",contextPath:/enterprise,isCoordinator:false)
processing.batching.size=1
total.candidate=2
non.updatable.fields=error.different
internal.cluster.node.id=node796599_796601
progress.interval=1
CSVLineCount=2
default.operation=merge
total.status.error=2
#ENDPROPERTIES
"Index","Identifier","Status","TransactionType","Result","Message"
"1","Candidate|create|224568907","error","candidate.create",,"The following email address is already used by a candidate included in the database: landers.samantha@target.com.;"

While importing CSV in powershell, I need to consider only from Column name ( "Index") and need to skip till #ENDPROPERTIES". There are no defined count for lines as each time the count may vary but every time I need to skip until "#ENDPROPERTIES". How do I achieve that?


回答1:


Something like this:

$csvpath = "C:\deleteme.csv"
$csvContent = Get-Content -Path $csvpath 
$LineNumber = $csvContent | Select-String '#ENDPROPERTIES' | Select-Object -ExpandProperty 'LineNumber'
$csvData = $csvContent | Select-Object -Skip $LineNumber | ConvertFrom-Csv


来源:https://stackoverflow.com/questions/48956245/powershell-import-csv-how-to-skip-until-particular-line-based-on-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!