Remove Special Characters from Import-Csv

Welcome Forums General PowerShell Q&A Remove Special Characters from Import-Csv

This topic contains 3 replies, has 4 voices, and was last updated by

 
Participant
3 years, 10 months ago.

  • Author
    Posts
  • #24171

    Participant
    Points: 0
    Rank: Member

    Hello

    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

    Moderator
    Points: 24
    Team Member
    Rank: Member

    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
    $Csv
    
  • #24173

    Keymaster
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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

    Participant
    Points: 0
    Rank: Member

    Thanks Guys. -Encoding was the issue.

The topic ‘Remove Special Characters from Import-Csv’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort