How can we avoid annoying gibberish (mojibake) in PSRemoting output ?

Serge Caron 70 Reputation points
2026-11-16T16:15:05.43+00:00

We use PowerShell Remoting (PSRemoting) for various maintenance tasks on member servers and workstations in a bilingual environment (English and French).

Output from Microsoft utilities are perfectly displayed in either language when run on the local console but diacritical characters are garbled when displayed through the WinRM (Windows Remote Management) tunnel used by PSRemoting.

Taking vssadmin as an example, the string

List Providers``        ``- Liste les fournisseurs enregistrés de clichés instantanés de volume

is displayed as

List Providers``        ``- Liste les fournisseurs enregistr‚s de clich‚s instantan‚s de volume

when vssadmin is running remotely.

In our case, it seems the [Console]::OutputEncoding.CodePage is set to 1252 (the default "ANSI code page") in the remote session while the local script is using codepage 850 (DOS Latin-1). Fair enough.

However, the utility running in the remote session is still using codepage 850 despite the [Console]::OutputEncoding.CodePage set to 1252. Hence the gibberish.

To illustrate this condition, the script below will PSRemote on the local machine and display the utility output (with gibberish) and translation to the caller’s [Console]::OutputEncoding.CodePage. In other words, a single computer is being used to display this behavior.

In this example, the lowercase e acute is at code point 130 in code page 850 and at code point 233 in code page 1252: translation is required.

The test script demonstrate that with manual translation, the proper output is displayed on the source console. This is accomplished with:

               $Encoding = [System.Text.Encoding]::Default                          # This is 1252 in this test
               $Output = [System.Text.Encoding]::GetEncoding([int]$SourceEncoding)  # This is 850 in this test
               $Output.GetString( $Encoding.GetBytes($MojiBake[$i].Line) )          # This is black magic!

Is there a way to avoid this “manual” translation ?

Sample output from the test script: 

Console Code Page: 850
 
Windows 10 Pro 26H2 (Build 26300.9711)
This is PowerShell  5.1.26100.9711
 
Caller's encoding: 850
Remote Console Code Page: 1252
 
The caller's encoding is used instead of the remote encoding: True
 
Test data:
List Providers        - Liste les fournisseurs enregistr‚s de clich‚s instantan‚s de volume
List Shadows          - Liste les clich‚s instantan‚s de volume existants
List ShadowStorage    - Liste les associations de stockage de clich‚s instantan‚s de volume
List Volumes          - Liste les volumes ‚ligibles pour les clich‚s instantan‚s
List Writers          - Liste les r‚dacteurs enregistr‚s de clich‚s instantan‚s de volume
 
Correct data:
List Providers        - Liste les fournisseurs enregistrés de clichés instantanés de volume
List Shadows          - Liste les clichés instantanés de volume existants
List ShadowStorage    - Liste les associations de stockage de clichés instantanés de volume
List Volumes          - Liste les volumes éligibles pour les clichés instantanés
List Writers          - Liste les rédacteurs enregistrés de clichés instantanés de volume

The test script:

$SomeScript = {
#	Param([Parameter(ValueFromPipeline=$True)][String[]]$SourceEncoding)
	Param([String]$SourceEncoding, [String]$SourceString)
###	Display OS and PowerShell versions
	$os = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
	Write-Output ""
	Write-Output "$($os.ProductName) $($os.DisplayVersion) (Build $($os.CurrentBuildNumber).$($os.UBR))"
	Write-Output "This is PowerShell  $($PSVersionTable.PSVersion -join ".")"
	Write-Output ""
### Display the source Encoding
	Write-Output "Caller's encoding: $SourceEncoding"
	
###	Display Remote Console CodePage
	Write-Output "Remote Console Code Page: $([Console]::OutputEncoding.CodePage)"
### Get some native output from this system
	$VSSAdmin = $( Invoke-Expression "vssadmin" | Select-String -Pattern 'List' -SimpleMatch )
	
###	Translate native output to ...
	$MojiBake = $VSSAdmin
	$Encoding = [System.Text.Encoding]::Default
	$Output = [System.Text.Encoding]::GetEncoding([int]$SourceEncoding)
	Write-Output ""
	Write-Output "The caller's encoding is used instead of the remote encoding: $($Output.GetString( $Encoding.GetBytes($MojiBake[0].Line) ) -ceq $SourceString)"
	# Note: Output already contains newline characters.
	Write-Output ""
	Write-Output "Test data:"
	for ($i = 0; $i -lt $MojiBake.Count; $i++) { $MojiBake[$i].Line }
	Write-Output ""
	Write-Output "Correct data:"
	for ($i = 0; $i -lt $MojiBake.Count; $i++) { $Output.GetString( $Encoding.GetBytes($MojiBake[$i].Line) ) }
}
### Target System and User credentials authorized via WinRM
$computer = "localhost"
$Credential = Get-Credential -Message "Enter the credentials required to run on the remote system"
###	Display Console CodePage and reference string, presuming the first line contains diacritical characters
	Write-Output "Console Code Page: $([Console]::OutputEncoding.CodePage)"
	$Reference = $( Invoke-Expression "vssadmin" | Select-String -Pattern 'List' -SimpleMatch )[0]
	
### Connect User to Target and execute script
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Invoke-command -computername $computer -Credential $Credential -ScriptBlock $SomeScript -ArgumentList $([Console]::OutputEncoding.CodePage), "$Reference"
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

4 answers

Sort by: Most helpful
  1. Serge Caron 70 Reputation points
    2026-11-19T21:43:05.5+00:00

    The output from stdout in the remote session is translated to UTF-8 as noted by Jordan Borean in https://github.com/PowerShell/PowerShell/issues/15128:

    This is all happening on the remote side, anything exchanged across PSSessions are in a utf-8 encoded CLIXML payload so there's no chance of an encoding mismatch between the client and the server. We just need to make sure that the remote PowerShell session captures the stdout from the process properly before it is serialised as a string to the CLIXML.

    The output from stdout in the remote session is coded using an unspecified multi bytes code page. Mojibake is observed when these strings are displayed "as is" across the Powershell session.

    When this output (sequence of characters) is properly encoded into a sequence of bytes, we recover the [System.Text.Encoding]::Default encoded value as an intermediary step.

    Decoding this data using the system locale $(Get-WinSystemLocale).TextInfo.OEMCodePage restores the intended output from the native utility. To be clear, you get the UTF-8 representation of the intended output. This is the goal.

    In a remote PowerShell session, we have no idea of the character sets in use. Basically, you would need to review in your script any and all output from a native utility:

    1. your native output = $(stdout from a native utility command line)
    2. $Encoding = [System.Text.Encoding]::Default
    3. $SourceEncoding = $(Get-WinSystemLocale).TextInfo.OEMCodePage
    4. $Output = [System.Text.Encoding]::GetEncoding([int]$SourceEncoding)
    5. $Output.GetString( $Encoding.GetBytes( your native output ) )

    All of this is happening transparently on the local console and you may not be aware of the gibberish displayed from a random remote system until you see it.

    Note the call to Get-WinSystemLocale: the OEM codepage is set on the remote system. Connecting the test script below to different servers yields the correct result regardless of this issue. Shown below are results from two distinct servers using codepages 850 and 437.

    Now, why this has to be done for remote session as opposed to local session is still a mystery to me.

    Enjoy!

    Windows Server 2025 Standard 24H2 (Build 26100.33650)
    This is PowerShell  5.1.26100.33648
    
    Remote Console Output Encoding is READ ONLY: True
    Remote Console Output Encoding is System encoding : True
    
    Testing if captured characters using iso-8859-1 are restored to UTF-8 values through ibm850:
    Test codepoint for à: True
    Test codepoint for â: True
    Test codepoint for è: True
    Test codepoint for ê: True
    Test codepoint for é: True
    Test codepoint for ô: True
    Test codepoint for ù: True
    
    Windows Server 2022 Standard 21H2 (Build 20348.5761)
    This is PowerShell  5.1.20348.5756
    
    Remote Console Output Encoding is READ ONLY: True
    Remote Console Output Encoding is System encoding : True
    
    Testing if captured characters using iso-8859-1 are restored to UTF-8 values through IBM437:
    Test codepoint for à: True
    Test codepoint for â: True
    Test codepoint for è: True
    Test codepoint for ê: True
    Test codepoint for é: True
    Test codepoint for ô: True
    Test codepoint for ù: True
    
    

    Test script: (Replace localhost by any computer able to do PSRemoting ;-)

    Invoke-Command -ComputerName localhost -ScriptBlock {
    ###	Display OS and PowerShell versions
    	$os = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
    	Write-Output ""
    	Write-Output "$($os.ProductName) $($os.DisplayVersion) (Build $($os.CurrentBuildNumber).$($os.UBR))"
    	Write-Output "This is PowerShell  $($PSVersionTable.PSVersion -join ".")"
    	Write-Output ""
    
    	Write-Output "Remote Console Output Encoding is READ ONLY: $([Console]::OutputEncoding.IsReadOnly)"
    	Write-Output "Remote Console Output Encoding is System encoding : $([Console]::OutputEncoding -eq [System.Text.Encoding]::Default)"
    	$Encoding = [System.Text.Encoding]::Default
    	Write-Output ""
    	
    ### Presume legacy code page
    	$SourceEncoding = $(Get-WinSystemLocale).TextInfo.OEMCodePage
    	$Output = [System.Text.Encoding]::GetEncoding([int]$SourceEncoding)
    
    ###	List sparse codepoints
    	$CodePoint = @()
    	$CodePoint += @("à", 8230)
    	$CodePoint += @("â", 402)
    	$CodePoint += @("è", 352)
    	$CodePoint += @("ê", 710)
    	$CodePoint += @("é", 8218)
    	$CodePoint += @("ô", 8220)
    	$CodePoint += @("ù", 8212)
    
    ###	Test text restore
    	Write-Output "Testing if captured characters using $([System.Text.Encoding]::Default.BodyName) are restored to UTF-8 values through $($Output.BodyName):"
    	For ($i = 0; $i -lt $CodePoint.Count; $i = $i + 2) {
    		Write-Output "Test codepoint for $($CodePoint[$i]): $($CodePoint[$i] -eq $Output.GetString( $Encoding.GetBytes( @([char] $CodePoint[$i + 1] ) ) ))"
    	}
    	Write-Output ""
    
    }
    
    

    Was this answer helpful?


  2. Serge Caron 70 Reputation points
    2026-11-18T22:51:13.16+00:00

    Hello Ronald,

    In this answer, I am a bit closer to the issue.

    The output from stdout in the remote session is translated to UTF-16 as noted elsewhere in these notes.

    However, looking at the character in position 56 of the source string (where we expect an e acute), we find the character 0x201A : this is a "Single low-9 quotation mark" according to the Unicode standard.

    This character is nowhere to be found in codepage 850: the fact that it translates to an e acute proves that there are special code points in the [System.Text.Encoding]::Default table.

    Again, the correct result is provided with $Output.GetString( $Encoding.GetBytes($MojiBake[$i].Line) ) : the presumed native text is decoded using 1252 and recoded using 850.

    Where can I find an actual description of this process/table/... ?

    Invoke-Command -ComputerName localhost -ScriptBlock {
    	Write-Output "Remote Console Output Encoding is READ ONLY: $([Console]::OutputEncoding.IsReadOnly)"
    	Write-Output "Remote Console Output Encoding is System encoding : $([Console]::OutputEncoding -eq [System.Text.Encoding]::Default)"
    	$Encoding = [System.Text.Encoding]::Default
    	Write-Output ""
    	
    ### Presume legacy code page
    	$SourceEncoding = 850
    	$Output = [System.Text.Encoding]::GetEncoding([int]$SourceEncoding)
    
    ### Get some native output from this system
    	$VSSAdmin = $( Invoke-Expression "vssadmin" | Select-String -Pattern 'List' -SimpleMatch )[0]
    	$MojiBake = $VSSAdmin
    	Write-Output "Legacy output in remote console:"
    	Write-Output $MojiBake[0].Line
    	Write-Output ""
    	
    ###	Translate native output to ...
    	Write-Output "Actual translation TO codepage $($Output.CodePage):"
    	$Output.GetString( $Encoding.GetBytes( $MojiBake[0].Line ) )
    	Write-Output ""
    
    	Write-Output "Value of the character at position 56 (e acute) above:"
    	[int] $MojiBake.Line.ToCharArray( 56, 1)[0] | Format-Hex -Encoding Unicode
    	Write-Output "Translation of this single character:"
    	$Output.GetString( $Encoding.GetBytes( @([char] 0x201A ) ) )
    
    }
    
    

    Output:

    Remote Console Output Encoding is READ ONLY: True
    Remote Console Output Encoding is System encoding : True
    
    Legacy output in remote console:
    List Providers        - Liste les fournisseurs enregistr‚s de clich‚s instantan‚s de volume
    
    Actual translation TO codepage 850:
    List Providers        - Liste les fournisseurs enregistrés de clichés instantanés de volume
    
    Value of the character at position 56 (e acute) above:
    
    
               Chemin d'accès :
    
               00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    
    00000000   1A 20                                            .
    Translation of this single character:
    é
    
    

    Was this answer helpful?


  3. Serge Caron 70 Reputation points
    2026-11-16T19:51:59.8933333+00:00

    Hello Ronald,

    Plase add the line

    Write-Output "Console Output Encoding is READ ONLY: $([Console]::OutputEncoding.IsReadOnly)"
    

    in your sample code.

    You will find that [Console]::OutputEncoding is READ ONLY and cannot be assigned.

    In my case, it is 1252.

    I have another test in mind once I go through your other references.

    Regards,

    Serge Caron

    Was this answer helpful?


  4. Ronald Sabiiti 2,250 Reputation points Independent Advisor
    2026-11-16T17:05:46.2+00:00

    Hi Serge,

    Based on the behavior observed, this appears to be related to how PowerShell Remoting handles output from legacy native utilities. In a WinRM session, native commands such as vssadmin may emit output using the system's OEM code page (for example, 850), while the remoting session interprets the output using a different encoding, resulting in incorrectly displayed accented characters.

    As a troubleshooting step, you can test whether explicitly setting the output encoding in the remote session improves the results:

    Invoke-Command -ComputerName $computer -ScriptBlock {
        [Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding(850)
        vssadmin list providers
    }
    

    Please note that this may not resolve the issue in all environments, as some native utilities do not fully honor the encoding settings when executed through PSRemoting.

    If the behavior persists, the manual encoding conversion demonstrated in your script is currently one of the most reliable workarounds. Where possible, we also recommend using PowerShell cmdlets or CIM/WMI-based alternatives instead of parsing output from legacy console utilities.

    For additional background, please refer to:

    Hope this helps!

    Ronald

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.