可以使用 Ansible 的 'win_command' 或者 'win_shell' 模块来运行 PowerShell 命令。需要注意的是,需要使用管理员权限来运行 PowerShell 命令,可以在 Ansible-playbook 中使用 'become' 或者 'become_method' 参数来指定。

例如:

- name: Run PowerShell command as administrator
  win_command: powershell.exe -Command 'Get-Process' #运行 Get-Process 命令
  become: yes #使用管理员权限运行
  become_method: runas #使用 runas 方法运行
Ansible: 以管理员身份运行 PowerShell 命令

原文地址: https://www.cveoy.top/t/topic/nniB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录