# running shell commands on Windows

**URL:** <https://forum.ansible.com/t/running-shell-commands-on-windows/22530>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [September 13, 2016, 7:53am UTC](https://forum.ansible.com/t/running-shell-commands-on-windows/22530 "2016-09-13T07:53:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [September 13, 2016, 7:53am UTC](https://forum.ansible.com/t/running-shell-commands-on-windows/22530/1 "2016-09-13T07:53:43Z")

</div>

Hello,

I did write an Ansible playbook to run on Linux, and now I would like to port it to run on Windows.

I would like to list the subdirectories to save it but because I don’t know the full name, on Linux did write this play:

- name: Lister l installation existante  
shell: chdir=/{{ Directoryname }} ls -d SHR\_4YOU-{{product}}-\*  
register: shr4you\_inst  
ignore\_errors: True  
when: repertoire.stat.isdir is defined and repertoire.stat.isdir

How can I port this line on Windows ? shell: chdir=/{{ Directoryname }} ls -d SHR\_4YOU-{{product}}-\*

Thanks for your help.  
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:** [September 14, 2016, 7:22am UTC](https://forum.ansible.com/t/running-shell-commands-on-windows/22530/2 "2016-09-14T07:22:12Z")

</div>

Hi,

Windows doesn’t have the same kind of shells as linux, so right now, your best choise is to write powershell and execute it from ansible using the raw or script modules. Powershell is a little different from bash or ksh. The main big difference is that you pipe objects not text.

Here’s a intro for someone coming from a linux background [https://developer.rackspace.com/blog/powershell-101-from-a-linux-guy/](https://developer.rackspace.com/blog/powershell-101-from-a-linux-guy/)

I like to use ad-hoc ansible to work out commands.

ansible win10 -m raw -a “gci c:\”

There are lot of aliases for command names that roughly approximate to linux equivalents, but because you are dealing with objects, the (default) output formats are very different from what you are used to. There’s a bunch of built in formatting commands which can help and you can pick out just the attributes from objects that you are interested in.

ansible 10t -m raw -a “gci c:\|format-list”

ansible win10 -m raw -a “gci c:\|convertto-csv”

ansible 10t -m raw -a “gci c:\|select Name, CreationTime |convertto-json”

Hope this gives you an idea of what is possible.

Jon

---

<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:** [September 15, 2016, 12:26pm UTC](https://forum.ansible.com/t/running-shell-commands-on-windows/22530/3 "2016-09-15T12:26:18Z")

</div>

By the way, this is useful if you are looking for ways to convert linux ‘toolbox’ commands to powershell equivalents:

[https://www.gitbook.com/book/devopscollective/a-unix-person-s-guide-to-powershell/details](https://www.gitbook.com/book/devopscollective/a-unix-person-s-guide-to-powershell/details)

Jon
