Run Powershell script on remote

Apologies for what must be a very dumb question, but how do I run a Powershell script which is located on a remote Windows machine? And, can I run a script that’s located on the Ansible host?

Many thanks!

You can use the ‘raw’ module to run a powershell script that is already on the remote machine (or any exe), and you can use the ‘script’ module to have ansible transfer the powershell script from your ansible controller to your managed host and then run the powershell script.

If possible though, use the windows modules for controlling your Windows machines (or create your own), they integrate better with the rest of ansible (you can take control of whether ansible returns ‘ok’ or ‘changed’ with your own module).

If you are able to clone ansible from github there are many useful examples of using raw, script and other windows modules in the test/integration/roles/ dirs

Hope this helps,

Jon

Thank you, Jon. I really appreciate the many contributions that you make to the list!