convert txt utf-8 to ansi - PowerShell - Spiceworks Community
文章推薦指數: 80 %
I have a system generation csv files but as UTF-8. I want a way to automatically convert the files in ANSI for use in a different system.
Home
News&Insights
News&InsightsHome
Innovation
ITCareers&Skills
Cloud
CyberSecurity
FutureofWork
AllCategories
Marketing
HR
Finance
Community
Askquestion
CommunityHome
SpiceworksOriginals
Cloud
Collaboration
Networking
WaterCooler
Windows
Allforums
How-Tos
Scripts
Vendors
Meetups
Reviews
OnlineEvents
Login
Join
Login
Join
Home
Programming
PowerShell
converttxtutf-8toansi
Postedbydidierodayo
Solved
PowerShell
IhaveasystemgenerationcsvfilesbutasUTF-8.IwantawaytoautomaticallyconvertthefilesinANSIforuseinadifferentsystem.anywaytoschedulethisusingwindowstaskandpowershellorbatfile?Source: C:\tempDestination:C:\convertedFilename:namesexport
Spice(2)
Reply(2)
flagReport
didierodayo
Thispersonisaverifiedprofessional.
Verifyyouraccount
toenableITpeerstoseethatyouareaprofessional.
anaheim
check
BestAnswer
francishagyard2
Thispersonisaverifiedprofessional.
Verifyyouraccount
toenableITpeerstoseethatyouareaprofessional.
thaipepper
PowerShellExpert
check
195
BestAnswers
thumb_up
347
HelpfulVotes
checkBestAnswer
I'mafraidyou'llhavetobemorespecificaboutwhichsystemyouwanttousethefileon,asANSIencodingdoesn'treallyexistitjustreferstothedefaultcodepageoftheOS(read:here)AsanexampleforASCIIyoucandoitlikethis:
Powershell
Get-Content-Path"C:\Temp\SourceFile.txt"|Out-File-FilePath"C:\Converted\DestFile.txt"-Encodingascii
Ifyouwanttoseeotheravailablechracterencodingoptionsusethis:
Powershell
Get-HelpOut-File-ParameterEncoding
Spice(4)
flagReport
2foundthishelpful
thumb_up
thumb_down
ViewBestAnswerinrepliesbelow
2Replies
francishagyard2
Thispersonisaverifiedprofessional.
Verifyyouraccount
toenableITpeerstoseethatyouareaprofessional.
thaipepper
PowerShellExpert
check
195
BestAnswers
thumb_up
347
HelpfulVotes
checkBestAnswer
I'mafraidyou'llhavetobemorespecificaboutwhichsystemyouwanttousethefileon,asANSIencodingdoesn'treallyexistitjustreferstothedefaultcodepageoftheOS(read:here)AsanexampleforASCIIyoucandoitlikethis:
Powershell
Get-Content-Path"C:\Temp\SourceFile.txt"|Out-File-FilePath"C:\Converted\DestFile.txt"-Encodingascii
Ifyouwanttoseeotheravailablechracterencodingoptionsusethis:
Powershell
Get-HelpOut-File-ParameterEncoding
Spice(4)
flagReport
2foundthishelpful
thumb_up
thumb_down
user930587
Newcontributor
pimiento
Get-ContentmightbenotoptimalforconvertingtexttoUTF-8asithandles
theinputfilelinebylineandmaycausechangingthelineending(for
example,ifyoumovetextfilesbetweenUnixandWindowssystems).Duetothis
behavior,Get-Contentisnotthebestchoiceaswell,ifperformance
matters. Youcansolvethisproblemby
usingtheRAWswitchwithGet-Contentasdescribedinthenextsection.
Orevenmoresimply,usetheRawswitchasdescribedheretoavoidthat
overheadandreadthetextinasingleblock:
Get-Content$inFile-Raw
Get-ContentC:\fso\MyFile.txt-Raw
Usingthe–RawparameterwithGet-Contentforces
WindowsPowerShelltoignorenewlinecharactersandend-of-linereturns,and
instead,returnthecontentsofthefileasonestring.
CorrectedCommand:
Get-Content
延伸文章資訊
- 1PowerShell 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...
- 2convert txt utf-8 to ansi - PowerShell - Spiceworks Community
I have a system generation csv files but as UTF-8. I want a way to automatically convert the file...
- 3File encoding - Mastering Windows PowerShell Scripting
File encoding Windows editors, including ISE, tend to save files using what is commonly known as ...
- 4Changing 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...
- 5PowerShell Studio tip: View and change file encoding