Windows Error Fix: WinRM Client Invalid Characters Response
Description of the Error
The error message "The WinRM client cannot process the request. The response received from the destination machine contains invalid characters and cannot be processed" typically occurs during remote management tasks using Windows Remote Management (WinRM) or PowerShell Remoting.
This issue arises when the remote server processes your command but returns output that contains unexpected byte sequences, non-ASCII characters, or ANSI escape codes (often used for text coloring or formatting by third-party command-line tools, scripts, or custom profiles). Because the WinRM XML parser expects standard compliant XML formatting, these raw, unescaped, or non-standard characters corrupt the stream, causing the client to reject the entire response.
Step-by-Step Fixes
Fix 1: Disable Custom Profiles and Text Formatting on the Remote Machine
If the user account you are connecting with has a custom PowerShell profile (\$PROFILE) or a Command Prompt initialization script that outputs text, banners, or colors upon login, it will break WinRM.
- Log into the remote machine directly (via RDP or physical access).
- Open PowerShell and check if a profile exists by running:
Test-Path $PROFILE - If it returns
\$True, open the profile file in Notepad:notepad $PROFILE - Comment out or remove any lines that generate visual output, print text banners, or modify text colors (such as third-party modules like
Oh-My-Posh). - Save the file and restart your WinRM connection.
Fix 2: Change Output Encoding to UTF-8
Forcing both the host and the remote machine to use UTF-8 encoding ensures that special characters do not get misinterpreted during transmission.
- On the local machine, open PowerShell as an Administrator.
- Run the following commands to set the environment to use UTF-8:
$OutputEncoding = [System.Text.Encoding]::UTF8 - Connect to the remote machine using your WinRM session.
- Execute the same two commands on the remote machine's session before running your primary script or command.
Fix 3: Suppress Warning, Error, and Verbose Streams in Your Commands
If a specific utility or command within your script outputs raw formatting characters into the error or warning pipelines, you can explicitly redirect or suppress those streams.
- Identify the command causing the issue inside your remote block.
- Append
6>null 7>nullor redirection parameters to prevent non-standard streams from polluting the XML output. For example:Invoke-Command -ComputerName "RemoteServer" -ScriptBlock { Get-TargetData 3>$null 4>$null` } - Alternatively, set the preference variables at the beginning of your script block:
\(WarningAction = 'SilentlyContinue'\)VerbosePreference = 'SilentlyContinue'
Fix 4: Restart the WinRM Service
A corrupted WinRM service state on either side can sometimes trigger parsing misbehaviors. Resetting the service clears the operational buffers.
- On the remote machine, open PowerShell as an Administrator.
- Restart the Windows Remote Management service by running:
Restart-Service WinRM -Force - On your local machine, open PowerShell as an Administrator and restart your local WinRM service as well:
Restart-Service WinRM -Force
ERROR_WSMAN_ENUMERATE_WMI_INVALID_KEY | ERROR_WSMAN_INVALID_FRAGMENT_PATH_BLANK | ERROR_WSMAN_KERBEROS_IPADDRESS | ERROR_WSMAN_CLIENT_WORKGROUP_NO_KERBEROS | ERROR_WSMAN_INVALID_BATCH_SETTINGS_PARAMETER
There may be some errors. Learn Microsoft