Solved

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

Posted on 2016-10-05
3
160 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Powershell command to read csv and remove license. 5 23
DFS issue 3 25
Check for Linux process in script 7 45
Ouput in html in powershell 2 18
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A brief introduction to what I consider to be the best editor for PowerShell.
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

792 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