community.windows.win_psexec – Runs commands (remotely) as another (privileged) user
This plugin is part of the community.windows collection (version 1.9.0).
You might already have this collection installed if you are using the
It is not included in
To check whether it is installed, run
ansible-galaxy collection list.
To install it, use:
ansible-galaxy collection install community.windows.
To use it in a playbook, specify:
Run commands (remotely) through the PsExec service.
Run commands as another (domain) user (with elevated privileges).
The below requirements are needed on the host that executes this module.
More information related to Microsoft PsExec is available from https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
The official documentation on the community.windows.psexec module.
The official documentation on the ansible.builtin.raw module.
The official documentation on the ansible.windows.win_command module.
The official documentation on the ansible.windows.win_shell module.
- name: Test the PsExec connection to the local system (target node) with your user community.windows.win_psexec: command: whoami.exe - name: Run regedit.exe locally (on target node) as SYSTEM and interactively community.windows.win_psexec: command: regedit.exe interactive: yes system: yes - name: Run the setup.exe installer on multiple servers using the Domain Administrator community.windows.win_psexec: command: E:\setup.exe /i /IACCEPTEULA hostnames: - remote_server1 - remote_server2 username: DOMAIN\Administrator password: some_password priority: high - name: Run PsExec from custom location C:\Program Files\sysinternals\ community.windows.win_psexec: command: netsh advfirewall set allprofiles state off executable: C:\Program Files\sysinternals\psexec.exe hostnames: [ remote_server ] password: some_password priority: low
Common return values are documented here, the following are the fields unique to this module: