How to get Child headers name

We have top 3 header li in CSV.

But want to skip the first line and take the second line as header i.e. Parent header.

Then, i want to take the third line as child header.

i wanted ParentHeader.childHeader = “XXXXX” then do “XXXX”

Not able to get ParentHeader.ChildHeader.

Please help!

shweta, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

This forum is for scripting questions rather than script requests.

What have you tried so far and why did it not work for you? You should post your code, a few sanitized but still representative lines of your input csv file and the error messages if you get some. Please format all of this as code using the code tags “PRE”. Thanks in advance.

A general tip: You could use Get-Content and Select-Object -Skip 2 to prepare your csv file to get used normaly with Import-Csv. :wink:

If you’re not familiar with this cmdlets you should read the complete help including the examples to learn how to use them.

 

VERSION 1 NEGATIVES SUPPORTED FALSE FILE ID 0200312133010
LINE ID HEADER PAYER SENDER
ID SourceEntityID SourceEntityIDType SourceElectronicServiceAddress ABN Organisational Name Text Family Name Address Phone State
1 184544 54584545 B=Valley 128575454 ABC Thomas Mel 48744 VIC
I want to use the second line header i.e. Payer and child header ABN and then take the value of ABN.

Something like Payer.ABN = “XXXX” then do “XXXX”

 

I have tried this

$csvData = Get-Content -Path $folderSourcePath | Select-Object -Skip 1 | ConvertFrom-Csv

but it is not giving child headers name but giving H4, H5

SENDER : 54651216324
H4 : Moonee Valley CC
H5 : Knez

shweta, please go back and fix your posts by formatting code and sample data as code.

You said you wanted the the 3rd row as your header. Why do you skip only 1 row in your command?

… Select-Object -Skip 1 …

I think it should be
… Select-Object -Skip 2 …

there are some challenges which i am going through:

  1. we have duplicate columns on line 3, if we change the column names then ok else error out but as per business process we can not modify CSV at all.
Solutions:
  1. whether i take the index number of the third line but can not do that as well (due to change in future)
  2. OR take the second line as parent header and third line as child header and try to find the value as ParentHeader.ChildHeader which i am not able to go through.
Please advise.

… me too … :wink:Please go back and format your code and sample data as code.

… that’s actually impossible for valid csv files …

… so you might change that business process if you have the need for your script to work and help the business with it. :wink:

… any future changes will likely break the functionality of a dependend process.

I don’t know what “ParentHeader” or “ChildHeader” is but there is a third option you may not have considered yet. Simply skip all 3 existing header rows and add your own ones with the parameter -Header of the cmdlet ConvertFrom-Csv.