How to fix "The WinRM Shell client cannot process the request. One of the argument value passed to the WSManRunShellCommand function is null or zero."
Description
This error occurs when you try to execute a remote command via Windows Remote Management (WinRM) or PowerShell Remoting, and the command invocation fails before it even starts executing on the target machine.
The core issue is that WinRM expects valid, non-empty arguments when initiating a shell command (WSManRunShellCommand). If your script, automation tool (like Ansible, Jenkins, or Azure DevOps), or manual CLI input passes an empty string (""), a null variable, or an improperly escaped parameter where a command or argument is explicitly required, WinRM rejects the request with this error. It can also be triggered by character encoding mismatches, corrupted WinRM session configurations, or strict policy restrictions on the remote host that strip out specific arguments during transit.
Step-by-Step Fixes
Fix 1: Check and Sanitize Your Command Arguments
Most frequently, this error is caused by a variable that evaluates to null right before the command is sent.
- Locate the script or task that triggered the error.
- Review the exact command string being passed to the remote host.
- Look for empty variables (e.g.,
Invoke-Command -ScriptBlock { & $executable $arguments }where$executableor$argumentshappens to be empty or null). - Hardcode a simple test command (like
whoamiorhostname) in place of your variables. - If the test command works, add validation logic to your script to ensure no arguments are null before executing, like this:
if (-not [string]::IsNullOrEmpty(\$myArgument)) { # Run your WinRM command here }
Fix 2: Re-register and Restart the WinRM Service
If the arguments are fine, the WinRM service configuration on either the client or the host might be glitched or out of sync.
- Click the Start menu, type
cmd, right-click Command Prompt, and select Run as administrator. - Stop the WinRM service by typing the following command and pressing Enter:
net stop winrm - Unregister the WinRM configuration to clear stuck states:
winrm unconfig - Re-initialize the default WinRM configuration and firewall exceptions:
winrm quickconfig -q - Restart the service to apply changes cleanly:
net start winrm
Fix 3: Fix Argument Escaping for Third-Party Automation (Ansible/Jenkins)
If you are hitting this error while using automation platforms to control Windows nodes, the issue usually lies in how quotes or special characters are processed.
- Open your configuration playbook or pipeline script.
- Check if you are passing commands with nested quotes (e.g.,
"powershell.exe -Command "Write-Output 'Hello'""). - Change the escaping style. For example, in Ansible, use the
win shellmodule instead of rawwin command, or wrap your PowerShell commands using the literal block scalar (|) to prevent YAML from converting arguments into null values:- name: Run powershell script safely ansible.windows.win shell: | \$path = "C:\Program Files\App" Start-Process -FilePath "\$path\run.exe"
Fix 4: Increase WinRM MaxShellsPerUser and MaxMemoryPerShell
Sometimes WinRM drops arguments or returns null internal pointers because it is running out of allocated operational resources.
- Open PowerShell as an Administrator on the target Windows machine.
- Check your current MaxShellsPerUser and MaxMemory configurations:
Get-Item WSMan:\localhost\Shell\* - Increase the memory limit per shell to prevent silent crashes during argument parsing:
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1024 - Increase the concurrent shell limit to ensure your process isn't being choked:
Set-Item WSMan:\localhost\Shell\MaxShellsPerUser 30 - Restart the WinRM service to apply the resource updates:
Restart-Service winrm
There may be some errors. Learn Microsoft