PowerShell Out-file Specify the method of file encoding _powershell

Source: Internet
Author: User

This article describes how to use PowerShell to create a text file, and the text file is encoded using UTF-8.

It's not easy to create a UTF-8 encoded file. Think about creating a UTF-8 encoded file in C # Hongo is a pain in the neck.

Later, after a careful thought, we can take this concept to a second. We can use Out-file this cmdlet to enter a string into a file to create a file, and when creating a file, specify its encoding as UTF-8.

In other words, we can get a UTF-8 encoded empty file using the following command.

Copy Code code as follows:
PS c:\users\spaybow> "" | Out-file-encoding UTF8 D:\2.txt

Note: After the-encoding parameter utf8, the middle cannot take the short horizontal line. Otherwise, you receive the following error message:

Copy Code code as follows:

PS c:\users\spaybow> "" | Out-file-encoding Utf-8 D:\2.txt
Out-file: Cannot perform parameter validation on parameter ' Encoding '. Parameter "Utf-8" does not belong to Validateset
property to specify the collection "Unicode,utf7,utf8,utf32,ascii,bigendianunicode,default,oem".
Please provide one of the parameters in this collection and retry the command.
Location: 1 Characters: 24
+ "" | Out-file-encoding <<<< Utf-8 D:\2.txt
+ Categoryinfo:invaliddata: (:) [Out-file], Parameterbindingval
Idationexception
+ Fullyqualifiederrorid:parameterargumentvalidationerror,microsoft.power
Shell.Commands.OutFileCommand

About PowerShell to create a utf-8 encoded file, this article on the introduction of so many, I hope to help you, thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.