Solved

Powershell Command to create a csv file using UTF-8 encoding

Posted on 2016-10-05
3
103 Views
Last Modified: 2016-10-05
I have a powershell command that is calling a sql query to create a csv file.  The file is being created as encoded as Unicode.  I need the file to be encoded as UTF-8.  Is there a command i can add to my code to have the file created as UTF-8?
0
Comment
Question by:jnikodym
  • 2
3 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 41830417
Which command you use to export the details?

If you are using Export-Csv to export the data to csv then you can use the -Encoding parameter..
Example..
< Your command > | Export-Csv C:\temp\report.csv -Encoding UTF8 -nti

Open in new window

0
 

Author Comment

by:jnikodym
ID: 41830423
Below is the code that exports the csv file

$outFile = "C:\iqs\customers.csv"
$result = GetSQL $query
$result | ConvertTo-Csv -Delimiter "|" -NoTypeInformation | % {$_.Replace('"','')} | Out-File $outFile

Open in new window

0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41830431
Out-File $outFile -Encoding UTF8 Should work..
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question