Fixing WinRM HTTP 400 Bad Request Error
The WinRM (Windows Remote Management) client throws an HTTP 400 Bad Request error when it attempts to establish a remote connection, but the target server rejects the formatting, size, or headers of the incoming request. Because the remote service does not provide additional details, this error typically stems from local configuration mismatches, corrupted WinRM listeners, SPN (Service Principal Name) issues, or oversized Kerberos authentication tokens.
Here is a step-by-step guide to diagnose and resolve this issue.
Step 1: Run the WinRM Quick Config Tool
The quickest way to fix corrupted listeners or basic service configuration issues is to let Windows automatically repair the WinRM setup.
- Click the Start menu, type
cmd, right-click Command Prompt, and select Run as administrator. - Type the following command and press Enter:
winrm quickconfig - If prompted to make changes or configure the firewall exceptions, type
yand press Enter.
Step 2: Clear the WinRM Client WinRM TrustedHosts List
An improperly configured TrustedHosts list can cause malformed request headers. Resetting or correctly configuring this list can resolve the communication breakdown.
- Open Command Prompt as an administrator.
- To allow communication with any host temporarily (for testing), run:
winrm set winrm/config/client @{TrustedHosts="*"} - Alternatively, if you want to restrict it to your specific target server, replace the asterisk with your target server IP or hostname:
winrm set winrm/config/client @{TrustedHosts="TARGET SERVER NAME"}
Step 3: Recreate the WinRM HTTP/HTTPS Listeners
If the default listeners on the remote machine are corrupted or bound to conflicting ports, deleting and recreating them fixes the underlying web service routing.
- Open Command Prompt as an administrator on the target machine.
- Check existing listeners by running:
winrm enumerate winrm/config/listener - Delete the broken HTTP listener:
winrm delete winrm/config/listener?Address=*+Transport=HTTP - Create a clean HTTP listener:
winrm create winrm/config/listener?Address=*+Transport=HTTP - Restart the WinRM service to apply changes:
net stop winrm && net start winrm
Step 4: Adjust MaxTokenSize for Kerberos Authentication
If you are connecting via a domain environment and your user account belongs to many Active Directory groups, your Kerberos authentication token might be too large. This causes the WinRM HTTP server to reject the packet as a "Bad Request".
- Press
Win + R, typeregedit, and press Enter to open the Registry Editor. - Navigate to the following path:
HKEY LOCAL MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\Kerberos\Parameters(Note: If theParameterskey does not exist, right-clickKerberos, select New > Key, and name it Parameters). - Right-click the
Parameterskey, select New > DWORD (32-bit) Value. - Name the new value
MaxTokenSize. - Double-click
MaxTokenSize, set the Base to Decimal, change the Value data to65535, and click OK. - Reboot your computer to apply the registry changes.
Step 5: Increase the Maximum Envelope Size
Sometimes the data structure payload transmitted via WinRM exceeds the default allowed configuration size, resulting in an immediate HTTP 400 error.
- Open Command Prompt as an administrator.
- Run the following command to increase the maximum envelope size to 1500 KB:
winrm set winrm/config @{MaxEnvelopeSizekb="1500"} - Test your remote connection again to see if the payload restriction was causing the issue.
There may be some errors. Learn Microsoft