Passing array or json as variable to powershell

Hi again,

New challenge!

How do I pass an array or json to a powershell script?

`

  • name: Test
    script: “{{ role_path }}/files/test.ps1 {{ object }}”

`

Example json:

`

{
“env01”: {
“path”: “C:\Program Files (x86)\Test”
}
}

`

Powershell param:

`

param(
[Parameter(Mandatory = $true)]
$object
)

`

I tried all kinds of things, but no luck so far.

What kind of yaml/jinja2 format does the array need to be for powershell to understand is an array object of sorts?

Have a look at the integration tests here for some examples of how you can pass args to the script module:

https://github.com/ansible/ansible/blob/devel/test/integration/targets/win_script/tasks/main.yml

If you have a lot of existing powershell maybe this is the way to go but be aware that you aren’t really ‘going with the grain’ if you use ansible just as way of delivering a lot of custom powershell to your windows hosts.
It might be all you need of course, but its worth exploring if the existing modules and check mode, and the idempotency logic in the existing modules have any value for you.

Hope this helps,

Jon

I only have one script that needs an array as input. This is the only way to make the script process dynamic content as I dont wanna call the script multple times with other variables.

Thanks for the link but I dont see any example with an array.