# Run powershell script on Windows servers which require Powershell to be run with admin privilages

**URL:** <https://forum.ansible.com/t/run-powershell-script-on-windows-servers-which-require-powershell-to-be-run-with-admin-privilages/24521>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [May 19, 2017, 8:31am UTC](https://forum.ansible.com/t/run-powershell-script-on-windows-servers-which-require-powershell-to-be-run-with-admin-privilages/24521 "2017-05-19T08:31:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashish\_Vijay](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Ashish\_Vijay](https://forum.ansible.com/u/Ashish_Vijay)\
**Post date:** [May 19, 2017, 8:31am UTC](https://forum.ansible.com/t/run-powershell-script-on-windows-servers-which-require-powershell-to-be-run-with-admin-privilages/24521/1 "2017-05-19T08:31:30Z")

</div>

Hello All,

I want to execute one powershell script on few target servers which require powershell to be run as administrator. I am getting access denied error when i try with normal playbook.

- name: Install software on Wndows Remote server.  
hosts: all  
tasks:

- name: copy script  
win\_copy:  
src: /tmp/install.ps1  
dest: c:\temp\install.ps1

- name: run a powershell script  
script: install.ps1 -Install -arg ‘{{ ARGLIST }}’  
register: out1

- debug: var=out1

I am getting access denied error when i try to execute this playbook.

---

<div class="post-metadata">

**Author:** ![Trond\_Hindenes](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Trond\_Hindenes](https://forum.ansible.com/u/Trond_Hindenes)\
**Post date:** [May 22, 2017, 5:40pm UTC](https://forum.ansible.com/t/run-powershell-script-on-windows-servers-which-require-powershell-to-be-run-with-admin-privilages/24521/2 "2017-05-22T17:40:26Z")

</div>

There’s no such thing as UAT/“run as admin” when using WinRM (which Ansible does). What does your script do, exactly?

---

<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:** [May 22, 2017, 8:07pm UTC](https://forum.ansible.com/t/run-powershell-script-on-windows-servers-which-require-powershell-to-be-run-with-admin-privilages/24521/3 "2017-05-22T20:07:45Z")

</div>

I could be wrong but when calling script it looks locally on the Ansible box and not the windows one. Can you specify your script without using win\_copy and see what happens?

---

<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:** [May 23, 2017, 4:41pm UTC](https://forum.ansible.com/t/run-powershell-script-on-windows-servers-which-require-powershell-to-be-run-with-admin-privilages/24521/4 "2017-05-23T16:41:17Z")

</div>

hosts: all

will try and run on all hosts in your inventory. These are unlikely to be all windows hosts.

I suggest limiting just to windows host to start with. -l option.

Also how are you running the playbook? what command line is used? where is ‘ARGLIST’ defined?

Jon
