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

2 answers

Sort by: Most helpful
  1. 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?


  2. Ronald Sabiiti 2,000 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.