COnvertCSV creating issue

sns 9,251 Reputation points
2022-01-30T10:08:52.117+00:00

I have data in text file as below which have been saved to .txt from .xlsx file. You can see that text data in the file below.

I tried multiple times but every time I am getting below warning. Please help where is wrong, is it something wrong with file content.
169633-notabletogetrow.png

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Answer accepted by question author
  1. Andreas Baumgarten 129.4K Reputation points MVP Volunteer Moderator
    2022-01-30T10:25:29.953+00:00

    Hi @sns ,

    it looks like in the line of "Contact = Ram" is a tab in the "Address City" column -> Hyd Hyderabad. Within a column of a tab separated file there should no tab inside the data.

    169568-image.png

    If it's not a tab but spaces it's fine.

    What are you trying to achieve with the two lines in the script?

    If you just want to read the content of the file with tab delimited data you can use this:

    $rows = Import-Csv -Delimiter "`t" -Path "c:\users\kumar\downloads\Customers.txt"  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


1 additional answer

Sort by: Most helpful
  1. Rich Matheisen 48,026 Reputation points
    2022-01-30T20:13:33.56+00:00

    The error says that member "ac" is already present. But I don't see any "ac" in the first line of the file.

    Here's a small demonstration of how to reproduce that error:

    $text = "ac`tac", "ac1`tac2"
    $rows = ConvertFrom-Csv -Delimiter "`t" -InputObject $text
    

    The screenshot of your Customers.txt file content does not agree with the error. Are you sure you're dealing with the correct file?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.