none
Import-CSV - A bug in v3?

    Question

  • I have a script that works fine in v2 of Power shell. In v3 though it fails with an error.

    Get-ChildItem -filter *cluster.csv | Import-Csv

    v3 error...

    Import-Csv : You must specify either the -Path or -LiteralPath parameters, but not both.At line:1 char:36+ Get-ChildItem -filter *Hosts.csv | Import-Csv+                                    ~~~~~~~~~~    + CategoryInfo          : InvalidData: (:) [Import-Csv], InvalidOperationException    + FullyQualifiedErrorId : CannotSpecifyPathAndLiteralPath,Microsoft.PowerShell.Commands.ImportCsvCommand


    Wednesday, September 04, 2013 8:38 AM

Answers

  • Hi,

    yes, I've seen that mentioned in some other places. I think it has something to do with the implicit member enumeration feature added in v3.

    #you can see what's actually happening under the hood in terms of parameter binding by using
    Trace-Command -Name ParameterBinding -Expression { Get-ChildItem -filter *.cluster.csv | Import-Csv } -PSHost
    
    #if you really wanted to dig into it you could compare the output in both versions
    
    #you can work-around the issue by using
    Get-ChildItem -filter *.cluster.csv | Select -expandProperty Name | Import-Csv
    

    • Marked as answer by Andrew J Palmer Wednesday, September 04, 2013 10:14 AM
    Wednesday, September 04, 2013 10:12 AM

All replies

  • Hi,

    yes, I've seen that mentioned in some other places. I think it has something to do with the implicit member enumeration feature added in v3.

    #you can see what's actually happening under the hood in terms of parameter binding by using
    Trace-Command -Name ParameterBinding -Expression { Get-ChildItem -filter *.cluster.csv | Import-Csv } -PSHost
    
    #if you really wanted to dig into it you could compare the output in both versions
    
    #you can work-around the issue by using
    Get-ChildItem -filter *.cluster.csv | Select -expandProperty Name | Import-Csv
    

    • Marked as answer by Andrew J Palmer Wednesday, September 04, 2013 10:14 AM
    Wednesday, September 04, 2013 10:12 AM
  • Awesome. Glad it's not me. Thanks for the workaround :D
    Wednesday, September 04, 2013 10:15 AM
  • Hi,

    yes, I've seen that mentioned in some other places. I think it has something to do with the implicit member enumeration feature added in v3.

    #you can see what's actually happening under the hood in terms of parameter binding by using
    Trace-Command -Name ParameterBinding -Expression { Get-ChildItem -filter *.cluster.csv | Import-Csv } -PSHost
    
    #if you really wanted to dig into it you could compare the output in both versions
    
    #you can work-around the issue by using
    Get-ChildItem -filter *.cluster.csv | Select -expandProperty Name | Import-Csv

    I'd like to add that this work around fails when Get-ChildItem returns paths that contain brackets (because apparently the Name property would get passed to Import-Csv as a -Path parameter).

    It seems the following should be done instead:

    Get-ChildItem -filter *cluster.csv | %{Import-Csv -LiteralPath $_}
    (Here, % is a short-hand for foreach.)


    Wednesday, August 12, 2015 5:13 AM