community.windows.win_psexec 模块 – 以其他(特权)用户身份运行命令(远程)
注意
此模块是 community.windows 集合(版本 2.3.0)的一部分。
如果您使用的是 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用: ansible-galaxy collection install community.windows。您需要其他要求才能使用此模块,有关详细信息,请参见 要求。
要在playbook中使用它,请指定: community.windows.win_psexec。
概要
- 通过PsExec服务(远程)运行命令。 
- 以其他(域)用户身份(具有提升的权限)运行命令。 
要求
执行此模块的主机需要以下要求。
- Microsoft PsExec 
参数
| 参数 | 注释 | 
|---|---|
| 从此(远程)目录运行命令。 | |
| 通过PsExec运行的命令行(限制为260个字符)。 | |
| 以提升的权限运行命令。 选项 
 | |
| PsExec实用程序的位置(如果它不在您的PATH中)。 默认值:  | |
| 运行命令的主机名。 如果未提供,则在本地运行命令。 | |
| 运行程序,以便它与远程系统上的桌面交互。 选项 
 | |
| 以受限用户身份运行命令(删除管理员组,只允许分配给用户组的权限)。 选项 
 | |
| 不显示启动横幅和版权信息。 这仅适用于特定版本的PsExec二进制文件。 选项 
 | |
| 在不加载帐户配置文件的情况下运行命令。 选项 
 | |
| 以其运行命令的(远程)用户的密码。 这是进行身份验证所必需的。 | |
| 用于以不同的优先级运行命令。 选项 
 | |
| 指定要使用的会话ID。 此参数与interactive一起使用。 当interactive设置为 | |
| 在系统帐户中运行远程命令。 选项 
 | |
| 连接超时(秒) | |
| 以其运行命令的(远程)用户。 如果未提供,则使用当前用户。 | |
| 等待应用程序终止。 仅用于非交互式应用程序。 选项 
 | 
备注
注意
- 有关Microsoft PsExec的更多信息,请访问 https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx 
另请参阅
另请参阅
- community.windows.psexec
- 基于PsExec模型在远程Windows主机上运行命令。 
- ansible.builtin.raw
- 执行低级命令。 
- ansible.windows.win_command
- 在远程Windows节点上执行命令。 
- ansible.windows.win_shell
- 在目标主机上执行shell命令。 
示例
- 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: true
    system: true
- 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
返回值
常见的返回值已在 此处 记录,以下是此模块特有的字段
| 键 | 描述 | 
|---|---|
| 模块使用的完整命令行,包括PsExec调用和其他选项。 返回:始终 示例:  | |
| PsExec创建的异步进程的PID。 返回:当  示例:  | |
| 命令的返回码。 返回:始终 示例:  | |
| 命令的错误输出。 返回:始终 示例:  | |
| 命令的标准输出。 返回:始终 示例:  | 
