4

When Executing native cmd command from powershell, e.g net view \\192.168.1.x I get the following results which non-English chars shown as ???? :

Share name        Type   Used as  Comment
--------------------------------------------------
AntEater          Disk
AntEater_Eab      Disk
HP  M4345 ?????   Print           HP  M4345 ?????
Letters           Disk
SMSCenter         Disk
temp              Disk
Users             Disk
????? ??? ??????  Print           ????? ??? ??????
The command completed successfully.

if I run chcp 862 I get the following results (on the console):

Share name        Type   Used as  Comment
--------------------------------------------------
AntEater          Disk
AntEater_Eab      Disk
HP  M4345 הנהחש   Print           HP  M4345 הנהחש
Letters           Disk
SMSCenter         Disk
temp              Disk
Users             Disk
מדפסת             Print           

Which is fine, but when I try to save it to a variable or export it to a file:

$temp = net view \\192.168.1.x
$temp

Share name        Type   Used as  Comment
--------------------------------------------------
AntEater          Disk
AntEater_Eab      Disk
HP  M4345 ?????   Print           HP  M4345 ?????
Letters           Disk
SMSCenter         Disk
temp              Disk
Users             Disk
????? ??? ??????  Print           ????? ??? ??????

the results are wrong again,

I've already tried:

net view \\192.168.1.x | Out-File C:\temp.txt -Encoding Unicode
cmd /c 'chcp 862 && net view \\192.168.1.x' | Out-File C:\temp.txt -Encoding Unicode
cmd /c 'chcp 862 && net view \\192.168.1.x > c:\temp.txt'
cmd /u /c 'chcp 862 && net view \\192.168.1.x > c:\temp.txt'

and much more really...

The Issue shown as well when running net view \\192.168.1.x | Out-String

The same results are whether I run it from CMD or PowerShell

Do you know the behavior? how can I save the correct output to a variable or file?

4
  • What about looking at this then.... stackoverflow.com/questions/10931984/…. Same as what I was trying to say perhaps with more explanation. Commented Dec 29, 2015 at 13:25
  • Looks like it is problem with net command: it does not honor console code page when output has redirected. You can compare output of net view \\192.168.1.x and net view \\192.168.1.x|more in CMD prompt. Commented Dec 29, 2015 at 13:32
  • @PetSerAl i guess you right, any idea then? Commented Dec 29, 2015 at 13:39
  • @Matt thanks, didn't find there any solution though Commented Dec 29, 2015 at 13:40

1 Answer 1

1

After changing the "language for non-Unicode programs" in the control panel, the problem solved, thanks for your help...

enter image description here

Run intl.cpl and select the Adminstrative tab.

Sign up to request clarification or add additional context in comments.

1 Comment

Set-WinSystemLocale he-IL

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.