2020年4月

一些powsershell脚本

1:powershell下载jdk
powershell (new-object System.Net.WebClient).DownloadFile( 'https://dl.softmgr.qq.com/original/Development/jdk-8u191-windows-x64-8.0.1910.12.exe','c:\j.exe')

2:windows上静默安装jdk
c:\j.exe /s ADDLOCAL="ToolsFeature,SourceFeature,PublicjreFeature"

注意:上面的地址根据实际情况更换。在windows server 2012上测试通过

ansible控制windows机器

windows上准备:
我的环境是windows server 2012,上面的powershell和winrm都是现成可用的。简单配置winrm即可:

winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'

上面如果没有执行,在ping的时候可能会报:the specified credentials were rejected by the server

ubuntu16.04上准备:
首先确保已经安装了ansible
如果是报错:winrm or requests is not installed: No module named winrm。则安装下面

apt install python-pip
pip install "pywinrm>=0.1.1"

如果报错:AttributeError: 'module' object has no attribute 'SSL_ST_INIT'

rm -rf /usr/lib/python2.7/dist-packages/OpenSSL
rm -rf /usr/lib/python2.7/dist-packages/pyOpenSSL-0.15.1.egg-info
sudo pip install pyopenssl

最后使用ansible ping一下看看,如果通了就说明是OK的。