Powershell 7 out-file over LAN result in strange characters

Welcome Forums General PowerShell Q&A Powershell 7 out-file over LAN result in strange characters

Viewing 5 reply threads
  • Author
    Posts
    • #265283
      Participant
      Topics: 1
      Replies: 2
      Points: 16
      Rank: Member

      Hi,

      When append data to a txt file over our Local Area Network using Out-File in Powershell 7, the data is transform in strange characters. If I use the same code in Powershell 5.1 the appended data comes normal.

      I also tried Out-File -encoding Ascii with the same result

      <u>BUT</u> if I append data to the Local Machine using Powershell 7, the appended data is as expected.

      Can someone help me to resove the problem?

      Partial Code Out-File
      @{Label=”Date & Time”.PadLeft(16) ;expression={$dDate}; align = ‘right’} | Out-File -Append –FilePath “\\fzafs01\UserData\Administrator\PowerShell\data\serversDisksSize.txt”

      Strange characters over LAN
      ਍潃灭瑵牥†楄歳匠穩⡥执
唠敳木⥢䘠敲⡥执
†牆敥┠†††慄整☠吠浩൥ⴊⴭⴭⴭⴭⴠⴭ‭ⴭⴭⴭⴭⴠⴭⴭⴭ‭ⴭⴭⴭⴭⴠⴭⴭⴭ‭ⴭⴭⴭⴭⴭⴭⴭⴭ਍婆ㅁ†††䌠›†ㄠ㘳㜮‰†㈠⸹㔸†ㄠ㘰㠮‵†㠷ㄮ┶ㄠ⼰㈲㈯㈰‰㌱㔺ഴ䘊䅚‱†††㩄††㔵⸸㌷†㈠㤸〮‹†㘲⸹㐶†㐠⸸㘲‥〱㈯⼲〲〲ㄠ㨳㐵਍婆ㅁ†††䘠›†㤠ㄳ㔮‱††⸰㐷†㤠〳㜮‷†㤹㤮┲ㄠ

    • #265424
      Participant
      Topics: 2
      Replies: 380
      Points: 513
      Helping Hand
      Rank: Major Contributor

      I have tested this by writing to a file share on a NAS and to a file share on another Windows machine and I cannot replicate the problem.

      Do you get the same problem if you try writing to a different server?

      If you use Wireshark you should see the SMB2 traffic, you can use Follow TCP Stream to see what data is being sent.  This will allow you to check if the correct data is leaving the device.

       

    • #265469
      Participant
      Topics: 1
      Replies: 2
      Points: 16
      Rank: Member

      I tried writing to a different server with the same result. B.t.w. the servers are Hyper-V virtual machines.

      I run the powershell code in Visual Studio Code application.

    • #265508
      Participant
      Topics: 2
      Replies: 380
      Points: 513
      Helping Hand
      Rank: Major Contributor

      I tested from the console host but it also works fine for me from VSCode.

      A Wireshark trace from the source computer should confirm the correct data leaves the computer.

      Have you tried doing it host-to-host on the Hyper-V machines to try and narrow it down to the Hyper-V infrastructure?  Presumably these servers are used for other things so I find it a bit odd that you don’t see corruption in other files or even the filenames themselves which I would expect if there was some problem with drivers or network adapters.

    • #265562
      js
      Participant
      Topics: 32
      Replies: 850
      Points: 2,751
      Helping Hand
      Rank: Community Hero

      Out-file doesn’t check the encoding of the file. I think it’s dangerous to append with it, and prefer add-content.

      4/19/19 out-file -append (or “>>”) can mix two encodings in the same file #9423 https://github.com/PowerShell/PowerShell/issues/9423

      • This reply was modified 1 month, 1 week ago by js.
    • #265592
      Participant
      Topics: 1
      Replies: 2
      Points: 16
      Rank: Member

      It works. I changed -Encoding from ASCII to UNICODE.

      Thanks for you help

Viewing 5 reply threads
  • You must be logged in to reply to this topic.