community.windows.win_psexec (2.2.0) — module

Runs commands (remotely) as another (privileged) user

Authors: Dag Wieers (@dagwieers)

Install collection

Install with ansible-galaxy collection install community.windows:==2.2.0


Add to requirements.yml

  collections:
    - name: community.windows
      version: 2.2.0

Description

Run commands (remotely) through the PsExec service.

Run commands as another (domain) user (with elevated privileges).


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Test the PsExec connection to the local system (target node) with your user
  community.windows.win_psexec:
    command: whoami.exe
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run regedit.exe locally (on target node) as SYSTEM and interactively
  community.windows.win_psexec:
    command: regedit.exe
    interactive: yes
    system: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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

Inputs

    
wait:
    default: true
    description:
    - Wait for the application to terminate.
    - Only use for non-interactive applications.
    type: bool

chdir:
    description:
    - Run the command from this (remote) directory.
    type: path

system:
    default: false
    description:
    - Run the remote command in the System account.
    type: bool

command:
    description:
    - The command line to run through PsExec (limited to 260 characters).
    required: true
    type: str

limited:
    default: false
    description:
    - Run the command as limited user (strips the Administrators group and allows only
      privileges assigned to the Users group).
    type: bool

session:
    description:
    - Specifies the session ID to use.
    - This parameter works in conjunction with I(interactive).
    - It has no effect when I(interactive) is set to C(no).
    type: int

timeout:
    description:
    - The connection timeout in seconds
    type: int

elevated:
    default: false
    description:
    - Run the command with elevated privileges.
    type: bool

nobanner:
    default: false
    description:
    - Do not display the startup banner and copyright message.
    - This only works for specific versions of the PsExec binary.
    type: bool

password:
    description:
    - The password for the (remote) user to run the command as.
    - This is mandatory in order authenticate yourself.
    type: str

priority:
    choices:
    - abovenormal
    - background
    - belownormal
    - high
    - low
    - realtime
    description:
    - Used to run the command at a different priority.
    type: str

username:
    description:
    - The (remote) user to run the command as.
    - If not provided, the current user is used.
    type: str

hostnames:
    description:
    - The hostnames to run the command.
    - If not provided, the command is run locally.
    elements: str
    type: list

noprofile:
    default: false
    description:
    - Run the command without loading the account's profile.
    type: bool

executable:
    default: psexec.exe
    description:
    - The location of the PsExec utility (in case it is not located in your PATH).
    type: path

interactive:
    default: false
    description:
    - Run the program so that it interacts with the desktop on the remote system.
    type: bool

Outputs

cmd:
  description: The complete command line used by the module, including PsExec call
    and additional options.
  returned: always
  sample: psexec.exe -nobanner \\remote_server -u "DOMAIN\Administrator" -p "some_password"
    -accepteula E:\setup.exe
  type: str
pid:
  description: The PID of the async process created by PsExec.
  returned: when C(wait=False)
  sample: 1532
  type: int
rc:
  description: The return code for the command.
  returned: always
  sample: 0
  type: int
stderr:
  description: The error output from the command.
  returned: always
  sample: Error 15 running E:\setup.exe
  type: str
stdout:
  description: The standard output from the command.
  returned: always
  sample: Success.
  type: str

See also