Winrm command execution is failing with Access denied

While trying to execute powershell command you might see an issue when command execution is failing with “Access is denied”.

INFO   2023-03-11 14:07:50    Initializing WinRM connection to windows host ...
INFO   2023-03-11 14:07:50    Connected to windows host
INFO   2023-03-11 14:07:50    Executing command ...
INFO   2023-03-11 14:07:50    
ERROR   2023-03-11 14:07:50    Access is denied.
INFO   2023-03-11 14:07:50    
INFO   2023-03-11 14:07:50    Command completed with ExitCode (1)

Here we can see the winrm connection worked fine but fails while execution of command, so we need to first understand the flow of winrm while using with Harness:

  1. Get connected to the target host using winrm
  2. Immediately next we run the script to set the runtime directory
  3. Before running any command on the target host we base64 each command

So here we see point 1 is succesfull, so in this case you can check below:

  1. Check and confirm if the working directory used here is correct and user under which winrm is configured has access to run command from that path
  2. Check if command used here is not something that is restrictive(like updating registry etc), change it with simple write-host and see if that works
  3. There is possibility that encoded command execution is blocked on your target host, then you can reach out to Harness support so that we can enable FF to not encode the command and run it as plain text