# win\_shell command execution

**URL:** <https://forum.ansible.com/t/win-shell-command-execution/31434>\
**Category:** Ansible Project\
**Created:** [October 8, 2019, 8:31am UTC](https://forum.ansible.com/t/win-shell-command-execution/31434 "2019-10-08T08:31:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Uppara\_venkat](https://avatars.discourse-cdn.com/v4/letter/u/6a8cbe/32.png) [@Uppara\_venkat](https://forum.ansible.com/u/Uppara_venkat)\
**Post date:** [October 8, 2019, 8:31am UTC](https://forum.ansible.com/t/win-shell-command-execution/31434/1 "2019-10-08T08:31:14Z")

</div>

Hi all,  
I’m trying to list the files with the name of “PackageDeploy” using as below but getting all other files also in the directory.

- win\_shell: ‘dir PackageDeploy\*.\* /b {{directory}}\configurations\jmxterm \> {{directory}}\configurations\temp’  
args:  
executable: cmd  
register: list\_out

Could you please suggest the right method for list the file with name ?

---

<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:** [October 8, 2019, 10:08pm UTC](https://forum.ansible.com/t/win-shell-command-execution/31434/2 "2019-10-08T22:08:06Z")

</div>

You would probably need to write like this:

- win\_shell: ‘dir PackageDeploy\*.\* /b \> {{directory}}\configurations\temp’

args:  
executable: cmd  
chdir: ‘{{directory}}\configurations\jmxterm’

register: list\_out

But its probably much better to use win\_find module [https://docs.ansible.com/ansible/latest/modules/win\_find\_module.htmld](https://docs.ansible.com/ansible/latest/modules/win_find_module.htmld) as the results will be easier to make use of than the contents of your list\_out registered variable.

- name: find PackageDeploy files  
win\_find:  
paths: ‘{{directory}}\configurations\jmxterm’  
patterns: ‘PackageDeploy\*.\*’  
register: package\_deploy\_info

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Uppara\_venkat](https://avatars.discourse-cdn.com/v4/letter/u/6a8cbe/32.png) [@Uppara\_venkat](https://forum.ansible.com/u/Uppara_venkat)\
**Post date:** [October 9, 2019, 10:48am UTC](https://forum.ansible.com/t/win-shell-command-execution/31434/3 "2019-10-09T10:48:19Z")

</div>

Thanks Jon, it’s working now
