# need to run powershell script without copying to target host

**URL:** <https://forum.ansible.com/t/need-to-run-powershell-script-without-copying-to-target-host/32717>\
**Category:** Ansible Project\
**Tags:** windows, rhel\
**Created:** [April 17, 2020, 5:10pm UTC](https://forum.ansible.com/t/need-to-run-powershell-script-without-copying-to-target-host/32717 "2020-04-17T17:10:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pavan\_Nr](https://avatars.discourse-cdn.com/v4/letter/p/8e8cbc/32.png) [@Pavan\_Nr](https://forum.ansible.com/u/Pavan_Nr)\
**Post date:** [April 17, 2020, 5:10pm UTC](https://forum.ansible.com/t/need-to-run-powershell-script-without-copying-to-target-host/32717/1 "2020-04-17T17:10:04Z")

</div>

Hi All,

i have machien Ansible running in RHEL 7  
Target host: Windows server 2019

i was able run powershell script by copying from RHEL to windows ,working fine

- name: Copy a single file  
win\_copy:  
src: “{{ playbook\_dir }}/files/test.ps1”  
dest: C:\Temp\test.ps1

- name: Run a script  
win\_shell: C:\temp\test.ps1

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [April 17, 2020, 7:22pm UTC](https://forum.ansible.com/t/need-to-run-powershell-script-without-copying-to-target-host/32717/2 "2020-04-17T19:22:33Z")

</div>

The proper way is to use the script module

`

- name: run script  
script: test.ps1

`

It will automatically try and find ‘test.ps1’ in various folder, the files folder adjacent to the playbook is one of them, copy it across, execute, then delete the file all in 1 go. If you truly don’t want to copy across the file then your only option is to read the script using the lookup plugin and use it with win\_shell

`

- name: run script in memory  
win\_shell: ‘{{ lookup(“file”, “test.ps1”) }}’

`

If this is a really large script you might read some command line length limits so it’s not always possible to do this.

---

<div class="post-metadata">

**Author:** ![Pavan\_Nr](https://avatars.discourse-cdn.com/v4/letter/p/8e8cbc/32.png) [@Pavan\_Nr](https://forum.ansible.com/u/Pavan_Nr)\
**Post date:** [April 17, 2020, 7:55pm UTC](https://forum.ansible.com/t/need-to-run-powershell-script-without-copying-to-target-host/32717/3 "2020-04-17T19:55:01Z")

</div>

Thanks Jordan, very informative, I will try options which you mentioned.
