Powershell版本要求及配置
- windows需要使用Powershell4.0及以上版本,入下图所示,如果不是4.0及以上的需要升级
![](https://img2020.cnblogs.com/blog/2098254/202011/2098254-20201120170327067-854751952.png)
一、升级Powershell至3.0+
1. 下载并安装Microsoft .NET Framework 4.5
https://download.microsoft.com/download/B/A/4/BA4A7E71-2906-4B2D-A0E1-80CF16844F5F/dotNetFx45_Full_setup.exe
2. 下载并安装PowerShell 3.0(Windows Management Framework 4.0
https://download.microsoft.com/download/E/7/6/E76850B8-DA6E-4FF5-8CCE-A24FC513FD16/Windows6.1-KB2506143-x64.msu
3. 重启Windows Server之后,打开PowerShell,查看升级是否成功,提示符界面输入:get-host
二、Windows开启winrm服务
1.查看powershell执行策略
get-executionpolicy (返回结果应该是:remotesigned)
2.更改powershell执行策略为remotesigned【输入y确认】
set-executionpolicy remotesigned
3.配置winrm service并启动服务
winrm quickconfig
4.修改winrm配置,启用远程连接认证【这里是PowerShell的命令,如果用cmd的话,@前面的' 和 末尾的' 要去掉的】
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
5.查看winrm service启动监听状态【如果有应答,说明服务配置并启动成功了】
winrm enumerate winrm/config/listener
三、关闭防火墙或者开放5985端口
四、测试
在清单文件中写入:
[windows]
192.168.26.133 ansible_ssh_user="Administrator" ansible_ssh_pass="Password" ansible_ssh_port=5985 ansible_connection="winrm" ansible_winrm_server_cert_validation=ignore
五、验证
[root@localhost ~]# ansible windows -m win_ping
172.50.1.172 | SUCCESS => {
"changed": false,
"ping": "pong"
}