Bootstrap FreeKB - Ansible - Run a command on Windows hosts using the win_command module
Ansible - Run a command on Windows hosts using the win_command module

Updated:   |  Ansible articles

If you are not familiar with modules, check out Ansible - Getting Started with Modules.

The shellcommand, script or raw modules are used to invoke a command on Linux nodes whereas win_command is used to run a common on Windows nodes.

In this example, the ps command will be invoked on the managed nodes. Often, this is used to run a Batch or PowerShell script on Windows nodes.

---
- hosts: all
  tasks:
  - name: run PowerShell example.ps1 script using win_command
    command: 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe F:\Scripts\PowerShell\example.ps1'
    register: out

  - debug:
      var: out
...

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 4aaed3 in the box below so that we can be sure you are a human.