How to specify encoding when creating Powershell text file ...
文章推薦指數: 80 %
I'm having an issue where the file is saved with encoding type Unicode - whereas I want the file to be saved as ANSI . This is a Powershell ... Searchsqlserver-dba.com Followsqlserver-dba.com *UsetheCommentssectionforquestions Daily&ExclusiveContent SQLServer-DBA.comLinks RecentPosts HowtoenableSQLServertraceflagsatstartup SQLServeruserrolesandpermissionsquery ListForeignKeysreferencingtablesinSQLServer DoesAWSRDSSQLServersupportDynamicManagementViews? WhatishorizontalpartitioninginSQLServer? ReasonsforTransactionLogBackupChainbreaking HashicorpVaultcurlforVBA Column-levelencryptionvsAlwaysencrypted Thesimpleguidetocolumn-levelencryption HelpwithPowershellfunctions SQLServerDBAJobs HowtospecifyencodingwhencreatingPowershelltextfileusingOut-file 02October,2019by TomCollins Question:I'vedeployedaPowershellscript-whichincludesaprocessto dumpoutaresultsettoacsvfile.I'mhavinganissuewherethefileissavedwithencodingtypeUnicode-whereasIwantthefiletobesavedasANSI.ThisisaPowershellcodesnippet,usingthePowershellcmdletOut-File (some_input)|select*-ExcludePropertyRowError,RowState,HasErrors,Name,Table,ItemArray|ConvertTo-Csv-NoTypeInformation|Select-Object-Skip1|Out-File-filepath myoutputfile.txt WhenI openthefileinNotepad-andattemptaSaveAs-theencodingdisplaysasUnicode. HowcanIforcePowershelltoencodeasANSI? Answer: It'spossibletoforcetheEncodingtypethroughextending the useofPowershellcmdletout-file.Thereisaparametercalled-Encoding.ThisistheadjustedPowershellcodesnippetyouoriginally posted.Theadjustedcodesnippetincludestheadditionofthe-EncodingparameteraspartofOut-File. TheinputdataispipedandaConvertTo-Csvisexecuted,pipedtoaSelectwhichskipsthefirstrow,andthenpipedtoanOut-File,includingtheexplicitEncoding (some_input)|select*-ExcludePropertyRowError,RowState,HasErrors,Name,Table,ItemArray|ConvertTo-Csv-NoTypeInformation|Select-Object-Skip1|Out-File-filepath -EncodingAsciimyoutputfile.txt lfyouexecuteyourcodeagain-andopeninNotepad-youshouldnowseeANSIastheEncodingtype LetmeknowifthisworksoranyothermethodsyoufoundtomanagetheEncodingtype ReadmoreonPowershellandcsvmanagement Export-CSVPowershell (SQLServerDBA) Howtowriteremove-itemresultstotextwith powershell out-file Powershell writetoWorddocument(SQLServerDBA) Author:TomCollins(http://www.sqlserver-dba.com) Share: PostedbyTomCollinsat9:18AM inPowershell | Permalink | Comments(0) VerifyyourComment PreviewingyourComment Postedby: | Thisisonlyapreview.Yourcommenthasnotyetbeenposted. Yourcommentcouldnotbeposted.Errortype: Yourcommenthasbeenposted.Postanothercomment Thelettersandnumbersyouentereddidnotmatchtheimage.Pleasetryagain. Asafinalstepbeforepostingyourcomment,enterthelettersandnumbersyouseeintheimagebelow.Thispreventsautomatedprogramsfrompostingcomments. Havingtroublereadingthisimage?Viewanalternate. PostacommentonHowtospecifyencodingwhencreatingPowershelltextfileusingOut-file (URLsautomaticallylinked.) YourInformation (Nameandemailaddressarerequired.Emailaddresswillnotbedisplayedwiththecomment.) Nameisrequiredtopostacomment Pleaseenteravalidemailaddress InvalidURL sqlserver-dba.com|SQLServerPerformanceTuning|SQLServerDBA:Everything|FAQ|Contact|Copyright&Disclaimer
延伸文章資訊
- 1ANSI Format - Micro Focus
- 2File encoding - Mastering Windows PowerShell Scripting
File encoding Windows editors, including ISE, tend to save files using what is commonly known as ...
- 3Changing source files encoding and some fun with PowerShell
The script detects encoding and saves file back in UTF-8. UPDATE: After I published the post I re...
- 4Thomson Data Analyzer - Save as ANSI Workaround (TDAv3.01)
- 5PowerShell Convert a File from utf-8 to ANSI (such as ...
(PowerShell) Convert a File from utf-8 to ANSI (such as Windows-1252). This example is to satisfy...