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!