Import-CSV - A bug in v3?

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


September 4th, 2013 8:38am

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
Free Windows Admin Tool Kit Click here and download it now
September 4th, 2013 10:12am

Awesome. Glad it's not me. Thanks for the workaround :D
September 4th, 2013 10:15am

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.)


Free Windows Admin Tool Kit Click here and download it now
August 12th, 2015 1:16am

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.)


August 12th, 2015 1:21am

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.)


Free Windows Admin Tool Kit Click here and download it now
August 12th, 2015 5:13am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics