Answers: <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>
  
Answers: CC BY-SA 4.0
Answers: 2024-06-14T09:20:47.607Z
Answers: Ansible 2.7 is EOL
Answers: bbaassssiiee
Answers: CC BY-SA 4.0
Answers: 2023-07-06T09:59:09.410Z
Answers: 2024-07-18T08:45:11.127Z
Answers: 2024-07-18T08:45:11.127Z
Answers: tintin
Body: <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>
  
Tags: <ansible><windows><powershell>
Title: how to run powershell script as windows administrator user using ansible
UserDisplayName: heyloitsmeraj
ThreadText: # 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  
  
  ---
  
  