Best way to so this is to write a module. This isn't as hard as it might sound. Have a look at win_environment.ps1 it's only about 30 lines of code. First bit checks the module parameters and sets up a $results variable, then the module does its thing and either returns a failure or adds info the the $results variable and completes, passing the results back to the ansible controller where they can be registered and used later in your playbook.
If you still want to write a script, most likely thing that might be messing things up is the fact that you need to be aware that PowerShell has the concept of an output pipe which can contain objects of varying types, and by default many PowerShell built in functions (also called CmdLets) default to sending objects to the output pipe. That's why sometimes you will see | Out-Null on the ends of some lines of the module code. Thus throws away unwanted objects and lets you control what is in the output pipe, so that only the things you need are converted into json to be returned to the ansible controller. Hope this helps, Jon -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/cada93e2-20c8-44ee-94f6-e730adc6a1d0%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
