Reputation: 149
I am using a script that runs on few computers, running Net command query on every one and comparing the results of any one with Compare-Object.
The script is:
Net users /domain
Some of the users in my environment has Spanish letters. When running the command locally, the output returns the user with the correct letters is spanish, But when running it remotely from another computer with Invoke-Command, the output of these specific users shows with symbols.
Example for user running locally:
Net users /domain
Adam Ñ
Example for user running running remotely with Invoke-Command:
Invoke-Command -Computername MyWin7Comp -scriptblock {
Net users /domain}
Adam ¥
I found a fix in Windows 10 1803 ONLY that has the option of using always UTF-8 Unicode. Windows 10 1803 option only
And it worked! running the script remotely ON this windows 10 1803 machine works perfectly, but I also want to run in on older versions...
What can I do?
Thank you
Upvotes: 2
Views: 2541
Reputation: 149
I managed to get it work. I was searching online for the answer and encountered this post: https://social.technet.microsoft.com/Forums/en-US/b92b15c8-6854-4d3e-8a35-51b4b56276ba/powershell-ise-vs-consoleoutputencoding?forum=ITCG
There was 1 answer that explained that when using PowerShell ISE (that that I was using basically), the console does not have actually a process for the console. that's why When I was trying to use Jeren Mostert and Theo answers, It was not working because there was not actually a console.
What I had to do is to run an EXE with Out-Null, this will open a process called "conhost.exe" which actually the console. Then ran [Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8 and eventually started the Invoke-Command which gave me an encoded result :)
The script I was running is:
Ping.exe | Out-Null
[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8
Invoke-Command -Computername MyW7Comp -ScriptBlock {Net Users /domain}
The result:
Adam Ñ
Upvotes: 2