locked
Import-Csv : Cannot convert 'System.Object[]' to the type 'System.Char' when reading from a .csv file RRS feed

  • Question

  • I am trying to read values from a .csv file using PowerShell to create Document Sets in SharePoint, but my code stalls when I get to this line

    $oData = Import-CSV H:\sample.csv -Header Name, Invoice Number,Order Number

    I get this error...

    Import-Csv : Cannot convert 'System.Object[]' to the type 'System.Char' required by parameter 'Delimiter'. Specified method is not supported.
    At C:\workspace\powershellscripts\Create-DocumentSets.ps1:8 char:62
    + $oData = Import-CSV H:\sample.csv -Header Name, Invoce Number,Order Number
    +                                                              ~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Import-Csv], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.ImportCsvCommand

    I am using a typical comma delimited csv file. Does anyone have any idea why I am getting this error? I really appreciate the help and ideas.

    Tuesday, December 1, 2015 9:53 PM

Answers

  • Does your input CSV have a header? If so, you don't need to specify one. If not, you'll need quotes since you're using spaces.

    • Proposed as answer by SitrucHtims Tuesday, December 1, 2015 9:59 PM
    • Marked as answer by Spawn10 Tuesday, December 1, 2015 10:15 PM
    Tuesday, December 1, 2015 9:58 PM

All replies

  • Does your input CSV have a header? If so, you don't need to specify one. If not, you'll need quotes since you're using spaces.

    • Proposed as answer by SitrucHtims Tuesday, December 1, 2015 9:59 PM
    • Marked as answer by Spawn10 Tuesday, December 1, 2015 10:15 PM
    Tuesday, December 1, 2015 9:58 PM
  • Thank you so much for the response Mike Laughlin...that was exactly the issue. Many thanks!
    Tuesday, December 1, 2015 10:14 PM
  • Cheers, you're very welcome. Glad I could help out.

    Tuesday, December 1, 2015 11:48 PM