# win\_command problems

**URL:** <https://forum.ansible.com/t/win-command-problems/23787>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [February 21, 2017, 3:20pm UTC](https://forum.ansible.com/t/win-command-problems/23787 "2017-02-21T15:20:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Norris](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@John\_Norris](https://forum.ansible.com/u/John_Norris)\
**Post date:** [February 21, 2017, 3:20pm UTC](https://forum.ansible.com/t/win-command-problems/23787/1 "2017-02-21T15:20:57Z")

</div>

Hi,  
so if I run on the command line, having used the inventory file to add user/password details under windows:vars  
ansible mesh -u user1 -m win\_shell -a “dir chdir=C:\Temp”

then I get

mesh | SUCCESS | rc=0 \>\>

Directory: C:\Temp

Mode LastWriteTime Length Name

But with a playbook

- name: Run a series of debug tasks to see the value of variables  
hosts: mesh  
user: user1  
tasks:
- name: list all the files in temp on c drive  
win\_command: dir  
args:  
chdir: c:\temp

I get  
TASK [list all the files in temp on c drive] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [mesh]: FAILED! =\> {“changed”: false, “cmd”: “dir”, “failed”: true, “msg”: “The system cannot find the file specified”, “rc”: 2}

The win\_command module docs show do not show escaping of backslashes or quotes.

What am I doing wrong?

Regards,  
John

---

<div class="post-metadata">

**Author:** ![Matt\_Davis](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Matt\_Davis](https://forum.ansible.com/u/Matt_Davis)\
**Post date:** [February 23, 2017, 5:10pm UTC](https://forum.ansible.com/t/win-command-problems/23787/2 "2017-02-23T17:10:00Z")

</div>

You’re using the wrong module. ‘dir’ isn’t a command, it’s a shell directive- you need to give that to Powershell or cmd.exe, so you need to use win\_shell. win\_command is for running an executable.

-Matt

---

<div class="post-metadata">

**Author:** ![John\_Norris](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@John\_Norris](https://forum.ansible.com/u/John_Norris)\
**Post date:** [February 23, 2017, 6:26pm UTC](https://forum.ansible.com/t/win-command-problems/23787/3 "2017-02-23T18:26:42Z")

</div>

Thanks for this Matt. Yes that makes a lot of sense.
