# Launch powershell script with argument by ansible

**URL:** <https://forum.ansible.com/t/launch-powershell-script-with-argument-by-ansible/23101>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [November 25, 2016, 3:39pm UTC](https://forum.ansible.com/t/launch-powershell-script-with-argument-by-ansible/23101 "2016-11-25T15:39:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jvieira](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@jvieira](https://forum.ansible.com/u/jvieira)\
**Post date:** [November 25, 2016, 3:39pm UTC](https://forum.ansible.com/t/launch-powershell-script-with-argument-by-ansible/23101/1 "2016-11-25T15:39:55Z")

</div>

Hi everyone,

My ansible version is : 2.2.0.0

I make a powershell script to deploy a new VM on vcenter.

Ansible correctly work with windows system but i have some trouble.

I would like ansible take my arguments for the script for each new host by the definition hots file in host\_vars

But I don’t know how to do that.

command line for ansible :  
ansible -i /etc/ansible/windows\_prod INTERNAL65 -m script -a /etc/ansible/roles/powershell/files/deploy.ps1

/etc/ansible/roles/powershell/files/deploy.ps1 :  
C:\AutoDeploy\final\_test.ps1 -VMName TEST-AUTO -Cluster Test -Template Windows2012-TMPL -User franck -Password garrot -HostName TEST-AUTO -IPeth0 xx.xx.xx.xx -SNMeth0 xx.xx.xx.xx -DNSPeth0 xx.xx.xx.xx -DNSSeth0 xx.xx.xx.xx

I try to change my argument by this method :

in /etc/ansible/roles/powershell/files/deploy.ps1 :  
C:\AutoDeploy\final\_test.ps1 -VMName {{ VMName }} -Cluster Test -Template Windows2012-TMPL -User franck -Password garrot -HostName {{ HostName }} -IPeth0 {{ IPeth0 }} -SNMeth0 {{ SNMeth0 }} -DNSPeth0 {{ DNSPeth0 }} -DNSSeth0 {{ DNSSeth0 }}

and in the definition host file i add arguments, for example :  
VMName: TEST-AUTO  
HostName: TEST-AUTO  
…

Finally that isn’t working.

If someone can help me …

Best regards.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [November 29, 2016, 8:49am UTC](https://forum.ansible.com/t/launch-powershell-script-with-argument-by-ansible/23101/2 "2016-11-29T08:49:58Z")

</div>

What error messages do you see?

Try running your playbook with -v or -vvvvvv to see variables being set and command being run.

---

<div class="post-metadata">

**Author:** ![Mike\_Fennemore](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@Mike\_Fennemore](https://forum.ansible.com/u/Mike_Fennemore)\
**Post date:** [November 29, 2016, 5:06pm UTC](https://forum.ansible.com/t/launch-powershell-script-with-argument-by-ansible/23101/3 "2016-11-29T17:06:01Z")

</div>

I’m not sure if it can be used from command line but seeing as you are using 2.2 perhaps try [https://docs.ansible.com/ansible/win\_shell\_module.html](https://docs.ansible.com/ansible/win_shell_module.html)
