https://www.jianshu.com/p/ac095497bad4
winRM服务是windows server下PowerShell的远程管理服务。Python脚本通过连接winRM模块操作windows命令行。
被控制windows server上winRM服务操作
> winrm e winrm/config/listener
> winrm quickconfig
> winrm set winrm/config/service/auth "@{Basic="true"}"
> winrm set winrm/config/service "@{AllowUnencrypted="true"}"
Python命令
import winrm
win2012 = winrm.Session('http://HOST_IP:5985/wsman', auth=('USER_NAME', 'USER_PWD'))
r = codecs.win2012.run_cmd('dir', encoding='utf-8')
print(r.std_out.decode())
关于winRM其他配置
> winrm set winrm/config @{MaxBatchItems="50"}
> winrm set winrm/config @{MaxEnvelopeSizekb="150"}
> winrm set winrm/config @{MaxTimeoutms ="60000"}
> winrm g winrm/config
> winrm s winrm/config/Client @{TrustedHosts="*"}
> winrm s winrm/config/Client/Auth @{Basic="true"}