1

I am capturing TCP packets using a Wireshark tool, TShark.exe. See below code example:

cd 'c:\program files\WireShark\'
.\tshark.exe -c 10
Capturing on 'Ethernet0'
1 0.000000 192.168.1.0 -> 192.168.2.0 TCP 60 49188 -> 445 [ACK]
1 0.000198 192.168.1.0 -> 22.14.2.0 TCP 60 53144 -> 3389 [ACK]

All ok so far, but now if storing in a variable:

$packets = .\tshark.exe -c 10
$packets
1 0.000000 192.168.1.0 ÅÖ% 192.168.2.0 TCP 60 49188 ÅÖ% 445 [ACK]

The directional arrows are lost and replaced with rogue characters. How can I preserve the formatting when storing in a variable?

user9924807
  • 707
  • 5
  • 22
  • It looks like an UTF-8 Codepoint (U+2192) mixed in with plain ASCII. I have no idea how to fix that but perhaps you could use one of the other output options and work from there (json pe). What are you trying to do? – Lieven Keersmaekers Feb 06 '20 at 11:30
  • This doesn't look normal, please supply more details on the OS, PowerShell version and IDE used. What happens if you try: `$packets = .\tshark.exe -c 10 | Out-String`? – iRon Feb 06 '20 at 16:37
  • 3
    I can reproduce this locally with tshark.exe - can you try running the following in the command prompt before you launch powershell: ```chcp 65001``` and see if that fixes it (it did for me...)? If it *does*, have a read of this answer here: https://stackoverflow.com/a/58964578/3156906 for what it's doing... – mclayton Feb 06 '20 at 22:45
  • @mclayton - fwiw - it fixes it for me too. – Lieven Keersmaekers Feb 07 '20 at 05:58
  • Have a look at [this answer](https://stackoverflow.com/a/60126275/1701026) as I believe that is the way to fix it from within PowerShell. – iRon Feb 08 '20 at 13:50

0 Answers0