Search code examples
powershellcsvpowershell-4.0import-csv

Import-CSV returns null


I have a CSV file which uses semi-colon delimeters, and is encoded as UTF-8 (no mark).

The following works as expected:

$fn = '\\path\to\file.csv'
ConvertFrom-Csv -Delimiter ';' -InputObject (get-content $fn -Encoding UTF8)

But the simpler expression returns null:

$fn = '\\path\to\file.csv'
import-csv $fn -Delimiter ';' -Encoding UTF8

Has anyone seen this behaviour before / any thoughts?


Solution

  • The issue was the input file's line end character.

    Viewing the file in Programmers' Notepad I was able to view the line end markers.

    They were carriage returns (i.e. MAC's preference for line endings).

    Replacing these with the Windows' style ending, carriage return + line feed, import-csv functioned as expected.