Trying to run ad-hoc tasks via Ansible/WinRM, need some help/guidance

I’m trying to leverage Ansible WinRM so that I can run ad-hoc tasks against the servers in my homelab environment.

These tasks would include but are not limited to

  • Windows Update Installation
  • Zero-Day mitigations
  • Batch software updates
  • Other Misc Breakfixes

I believe that I’ve gotten ansible itself functional and the properties for the winrm connection and service account properly configured but an not entirely sure execute PowerShell or bat commands against systems via it using Foreman. I can now connect to Windows Systems using WinRM, however trying to run code pasted into the command box against them results in a bunch of errors that the python interpreter couldn’t be found on the target host.

For Linux hosts I can do the following for ad-hoc tasks.

  • On the Hosts page,select the host(s) > Schedule Remote Job
  • Leave Category as Commands, Job Template as “Run Command- SSH Default”
  • Paste commands or .sh script into command field
  • Submit

Is there a similar process I can use for Windows systems via WinRM, or do I have to create and specify an ansible playbook? My ideal goal is to be able to paste one or a few lines of code into the command box and then run it, but not sure if that’s doable?


I never used ansible aganinst windows systems, so ymmv.

When you run a job against linux hosts, it uses the Run Command- SSH Default template which in turn uses the shell ansible module under the hood. The docs[1] for that module say

For Windows targets, use the[2] module instead.

Could you try cloning the original template and changing the module used there? Using the cloned and changed template could allow you to just paste ad-hoc commands into the command box when triggering the job.

[1] - – Execute shell commands on targets — Ansible Documentation
[2] - win_shell – Execute shell commands on target hosts — Ansible Documentation