0

I've followed the guide here: Use Windows PowerShell to Look for and Replace a Word in a Microsoft Word Document

My problem is that if I put a UTF8 string into the search filed it gets converted to ASCII before going into the word application.

If you simply copy and paste his code and change the find text to something like Japanese: カルシウム

It will go into work and search for the ascii equivalent: カルシウム

I have tried every suggestion about setting input and output to UTF8 that I can find but nothing seems to be working. I can't even get the powershell console to actually display Japanese characters, all I get are boxes. I think that might have something to do with the fact that I only have 3 fonts and perhaps none of them can display the Japanese characters in the console...but I don't care about that, I want to be able to send the Japanese characters in UTF8 for the find and replace.

Any Help?

2
  • 2
    For display: move to ISE - unlike PowerShell.exe it can handle characters from around the globe. That was initial reason why ISE came to be. For issue with your code: it would help to see the code itself. I suspect it may be issue with the way you save the script (or - again - with limitations of PowerShell.exe). Commented May 23, 2014 at 4:56
  • Links can be helpful as supplemental information, but please include the relevant code you're using in the question rather than sending readers off to read a blog post and then figure out how what you're describing in words applies to what's discussed there. Commented May 23, 2014 at 19:46

2 Answers 2

1

For people who keep getting output encoding to ASCII or Unicode all the time, you can set output encoding to whatever encoding you want from Microsoft blog $OutputEncoding

  1. PS C:\> $OutputEncoding //tells you what default encoding you have
  2. PS C:\> $OutputEncoding = [Console]::OutputEncoding //change to the console or you can set it
  3. $OutputEncoding = New-Object -typename System.Text.UTF8Encoding //whatever you want, look up japanese
  4. PS C:\> $OutputEncoding // verify the encoding
Sign up to request clarification or add additional context in comments.

Comments

0

The answer is actually quite easy. If the powershell-script is saved as UTF8, characters are not encoded correctly. You'd need to save the ps1-script encoded as "UTF8 with BOM" in order to get the characters right.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.