Remove Special Characters from Import-Csv

This topic contains 3 replies, has 4 voices, and was last updated by Profile photo of H Man H Man 2 years, 3 months ago.

  • Author
  • #24171
    Profile photo of H Man
    H Man


    I have a reporting system that generates a csv file that I need to import into powershell.

    While looking at the file it looks fine , But using import-csv some "special character " is detected in of of the proprieties. Is there anyway to remove this character : �

    here is the output
    Classification : CMS/NBS � Report � Revision

    it should be

    Classification : CMS/NBS » Report – Revision

  • #24172
    Profile photo of Daniel Krebs
    Daniel Krebs

    One option would be to replace the characters:

    $Content = Get-Content -Path C:\My\test.csv
    $Content = $Content.Replace('»','>').Replace('–','-')
    $Csv = ConvertFrom-Csv -InputObject $Content
  • #24173
    Profile photo of Don Jones
    Don Jones

    Those are extended characters, not ASCII, which is probably causing the problem. You might try using -Encoding to specify the type of encoding (since it isn't ASCII) that the file was created in. For example, "-Encoding UTF8," if that's what was used to create the file.

  • #24176
    Profile photo of H Man
    H Man

    Thanks Guys. -Encoding was the issue.

You must be logged in to reply to this topic.