Reading CSV with inconsistent formatting

I have a huge CSV file that’s 300MB, 250k rows. Reading it plaintext, the header row reads as follows:

IP,"DNS Host Name",Application,Version,Source,"Date First Found","Date Last Updated"

As you can see, there is a quotation around values that are more than one word.

I think this is causing a problem when reading it in. It always gives me the warning “One or more headers were not specified”. When I output what it read, it gives me just the IP addresses. When I specify the header I want with “-header”, the same thing occurs.

Another weird thing is that the first 5 lines are “Filters:”, “Asset Group:”, “IP Address or NetBlock:”, “Application:”, and “IP”, without the quotes. I don’t see “Filters:”, “Asset Group:”, or “IP Address or NetBlock:” anywhere in the CSV though. I have no clue where it’s getting them from.

I’m reading the file using:

Import-CSV "FileName.csv"

I also tried specifying the delimiter as “,” just to make sure nothing funky was going on.

You can try something like this to use your own headers.

$yourCSVvariable = get-content $InFile |select -skip 1 |convertFrom-csv -Header IP,DNSName,Application,Version,Source,FirstFound,LastUpdated

Please provide the first 5 lines of the csv file as in

Get-Content .\CSV1.csv  | select -First 5 

[quote quote=171505]Please provide the first 5 lines of the csv file as in

Get-Content .\CSV1.csv | select -First 5
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[/quote] It says this but I swear that's not what I see when I open it in Visual Studio Code or Wordpad. It would appear that the first line is empty, but I can't see how that's possible.
Filters:
"Asset Group:",N/A
"IP Address or NetBlock:",N/A
Application:,N/A

[quote quote=171496]You can try something like this to use your own headers.

$yourCSVvariable = get-content $InFile |select -skip 1 |convertFrom-csv -Header IP,DNSName,Application,Version,Source,FirstFound,LastUpdated

[/quote]
That works a lot better!