Import-Csv fails to bind Get-ChildItem output to its -LiteralPath parameter via the pipeline
See original GitHub issueRelated: #4472.
The -LiteralPath
parameter, via its -PSPath
alias, is normally used to bind to objects piped from Get-ChildItem
/ Get-Item
, such as with the Get-Content
cmdlet.
Import-Csv
currently fails to establish this binding.
Steps to reproduce
'file1.csv', 'file2.csv' | % { $null > $_ }
Get-ChildItem file*.csv | Import-Csv
Expected behavior
Binding of the [System.IO.FileInfo]
instances via their .PSPath
property to -LiteralPath
, and therefore no output (null collection), given that both files are empty.
Actual behavior
The following statement-terminating error is reported:
Import-Csv : You must specify either the -Path or -LiteralPath parameters, but not both.
Environment data
PowerShell Core v6.0.0-beta.4 on macOS 10.12.5
PowerShell Core v6.0.0-beta.4 on Ubuntu 16.04.2 LTS
PowerShell Core v6.0.0-beta.4 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.413 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Import-CSV returns null when piped files
Import -Csv accepts only strings (path) from the pipeline so in order to pipe directly to it you need to first expand the...
Read more >Import-Csv (Microsoft.PowerShell.Utility)
The Import-Csv cmdlet creates table-like custom objects from the items in CSV files. Each column in the CSV file becomes a property of...
Read more >How to use Import-CSV in PowerShell?
Learn how to import CSV files using PowerShell with this step-by-step guide. Master the art of data manipulation and analysis in no time!...
Read more >Import-Csv - PowerShell Command - PDQ
Learn how to use the Microsoft PowerShell command Import-Csv. PDQ breaks down uses of Import-Csv with parameters and helpful examples.
Read more >How do I open multiple files at once with Windows ...
To avoid this problem, the -LiteralPath parameter must be bound, which is most easily done by using the output from Get-ChildItem or ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Lipkau pointed me to this issue.
The problem appears to be with the way in which the parameter sets are done for this cmdlet. There are 2 parameter sets: One for Delimiter and another for Culture. Each set accepts both
-Path
and-LiteralPath
and then performs a runtime check for the presence of both.@SteveL-MSFT: Thanks for the feedback.
The 1st hit when I searched Stack Overflow for
[powershell] import-csv get-childitem
was a question from 2013 relating to this very bug: https://stackoverflow.com/q/18254718/45375I haven’t sifted through the remaining hits, but anecdotally I can tell you I’ve seen people run into the problem repeatedly.
Either way, it should be a simple bug to resolve, and given that the current behavior is simply broken, there should be no backward-compatibility concerns.