These two Ansible modules are the best way to send any PowerShell or bash commands to a Windows hosts. The win_shell module is more used for running scripts and long or multiline commands, while the command is more for running regular commands that may require extra parameters. The following playbook shows an example code:
- name: run a PowerShell script on a working
directory
win_shell: C:scriptsPSscript.ps1
args:
chdir: C:Userswinuser1Workspace
- name: execute a PowerShell command on remote
Windows hosts
win_command: (get-service wuauserv | select status
| Format-Wide | Out-String).trim()
register: output
- debug: var=output.stdout