<p>You can use</p>
<pre><code>become: yes
become_method: runas
</code></pre>
<p><a href="https://stackoverflow.com/a/48675395/15962190">https://stackoverflow.com/a/48675395/15962190</a></p>
<p><a href="https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_privilege_escalation.html#become-and-windows" rel="nofollow noreferrer">https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_privilege_escalation.html#become-and-windows</a></p>

CC BY-SA 4.0
2024-06-14T09:20:47.607Z
Ansible 2.7 is EOL
bbaassssiiee
CC BY-SA 4.0
2023-07-06T09:59:09.410Z
2024-07-18T08:45:11.127Z
2024-07-18T08:45:11.127Z
tintin
<p>i want to run a power shell script on remote windows machine. The PowerShell script will install software on C drive. The user which used to login is already in administrator group.</p>
<p>But when the command triggered manually in server it works but through ansible it is not working. The ansible task I have configured:</p>
<pre><code>tasks:
    - name: Execute PowerShell script
      win_shell: |
        powershell.exe -NoProfile -ExecutionPolicy Bypass -File &quot;C:\Path\to\your\script.ps1&quot;
</code></pre>
<p>Any help?</p>

<ansible><windows><powershell>
how to run powershell script as windows administrator user using ansible
heyloitsmeraj
# how to run powershell script as windows administrator user using ansible

(Asked by: username_0 on 2023-07-04)

i want to run a power shell script on remote windows machine. The PowerShell script will install software on C drive. The user which used to login is already in administrator group.
But when the command triggered manually in server it works but through ansible it is not working. The ansible task I have configured:
tasks:
    - name: Execute PowerShell script
      win_shell: |
        powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\Path\to\your\script.ps1"

Any help?

**Tags:** ansible, windows, powershell


---

## 1 answers

### Answer by username_1 on 2023-07-06. Score: 1

You can use
become: yes
become_method: runas

https://stackoverflow.com/a/48675395/15962190
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_privilege_escalation.html#become-and-windows

> **Comments:**
> **username_2**: Ansible 2.7 is EOL  

---

