Using PowerShell to change encoding of a .csv file.

Post Reply
KenCratty
Newbie
Posts: 9
Joined: Wed Feb 28, 2018 11:13 pm

Using PowerShell to change encoding of a .csv file.

Post by KenCratty »

I am trying to use PowerShell to change the encoding of a .csv file. This is what I have tried but it's not working.

First Attempt: (this works outside Switch)
Get-ChildItem *.csv | % { (Get-Content $_) | Set-Content "$($_.basename).csv" -encoding ASCII }

Second Attempt:
(Get-Content -Encoding UCS-2 LE BOM $FILENAME ) | Out-File -Encoding ANSI $FILENAME

Third Attempt:
get-content $yourfile | out-file $yourfile -encoding utf8

What am I doing wrong here? Any help would be much appreciated.
loicaigon
Advanced member
Posts: 364
Joined: Wed Jul 10, 2013 10:22 am

Re: Using PowerShell to change encoding of a .csv file.

Post by loicaigon »

Most issues in command line get fixed when you not only calling the command but specifying the whole path to the binary itself.
If it works in shell, it should work in Switch. Otherwise it's all about settings and not the command itself.
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Using PowerShell to change encoding of a .csv file.

Post by jan_suhr »

Switch can be a bit picky when it comes to Execute Command stuff, in some cases you have to run a shellscript (or BAT) file with your command in it to get it to work.

I have made an APP for this called "Execute Command Friend" and it let you construct Shellscripts or BAT files with Switch variables that you call from the Execute Command Configurator.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
Post Reply