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 中)。 默认:  | |
| 运行命令的主机名。 如果未提供,则命令将在本地运行。 | |
| 运行程序,以便它与远程系统上的桌面交互。 选择 
 | |
| 以受限用户身份运行命令(删除 Administrators 组,并且仅允许分配给 Users 组的权限)。 选择 
 | |
| 不显示启动横幅和版权消息。 这仅适用于特定版本的 PsExec 二进制文件。 选择 
 | |
| 运行命令而不加载帐户的配置文件。 选择 
 | |
| 要以其身份运行命令的(远程)用户的密码。 为了验证您的身份,这是强制性的。 | |
| 用于以不同的优先级运行命令。 选择 
 | |
| 指定要使用的会话 ID。 此参数与 interactive 结合使用。 当 interactive 设置为  | |
| 在 System 帐户中运行远程命令。 选择 
 | |
| 连接超时时间(秒) | |
| 要以其身份运行命令的(远程)用户。 如果未提供,则使用当前用户。 | |
| 等待应用程序终止。 仅用于非交互式应用程序。 选择 
 | 
备注
注意
- 有关 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。 返回: 当  示例:  | |
| 命令的返回代码。 返回: 始终 示例:  | |
| 命令的错误输出。 返回: 始终 示例:  | |
| 命令的标准输出。 返回: 始终 示例:  | 
