# Run Repadmin on the Domain controller from ansible task server

**URL:** <https://forum.ansible.com/t/run-repadmin-on-the-domain-controller-from-ansible-task-server/36076>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [December 6, 2021, 5:22pm UTC](https://forum.ansible.com/t/run-repadmin-on-the-domain-controller-from-ansible-task-server/36076 "2021-12-06T17:22:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nitrous](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@Nitrous](https://forum.ansible.com/u/Nitrous)\
**Post date:** [December 6, 2021, 5:22pm UTC](https://forum.ansible.com/t/run-repadmin-on-the-domain-controller-from-ansible-task-server/36076/1 "2021-12-06T17:22:04Z")

</div>

I am trying to figure out, how to run repadmin on the Domain controller itself:

- name: Sync Active Directory With New Changes  
ansible.windows.win\_shell: repadmin /syncall ‘{{ server.domain }}’ /AdeP  
become: yes  
become\_method: runas  
become\_user: ‘{{ server.domain }}\username’

The above tries to run on the task server, that has the AD modules installed, but I would like to run the above on the domain  
controller itself.

Would we use the delegate option and then specify the Domain controller? Thanks

---

<div class="post-metadata">

**Author:** ![Nitrous](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@Nitrous](https://forum.ansible.com/u/Nitrous)\
**Post date:** [December 6, 2021, 6:15pm UTC](https://forum.ansible.com/t/run-repadmin-on-the-domain-controller-from-ansible-task-server/36076/2 "2021-12-06T18:15:24Z")

</div>

This works from the ansible task server using powershell:

$password = “xxx” | ConvertTo-SecureString -asPlainText -Force  
$username = “xx\xxxxx”  
$credential = New-Object System.Management.Automation.PSCredential($username,$password)  
Invoke-Command -ComputerName DC01 -credential $Credential -ScriptBlock { repadmin /syncall /AdeP }

How can I use the above to be able to use it using the ansible.windows.win\_shell module, in ansible? Thanks

---

<div class="post-metadata">

**Author:** ![Nitrous](https://avatars.discourse-cdn.com/v4/letter/n/dfb087/32.png) [@Nitrous](https://forum.ansible.com/u/Nitrous)\
**Post date:** [December 7, 2021, 4:40pm UTC](https://forum.ansible.com/t/run-repadmin-on-the-domain-controller-from-ansible-task-server/36076/3 "2021-12-07T16:40:02Z")

</div>

I managed to figure out how to do this, if anyone is interested, used invoke-command:

- name: Sync Active Directory With New Changes  
ansible.windows.win\_shell:  
Invoke-Command -ComputerName ‘{{ server.dc }}’ -ScriptBlock { repadmin /syncall /AdeP }  
become: yes  
become\_method: runas  
vars:  
ansible\_become\_user: ‘{{ server.domain }}\username of a domain admin account’  
ansible\_become\_password: ‘{{ ansible\_password }}’  
become\_user: “{{ server.domain }}\username of a domain admin account”
