python winrm模块使用

时间:2015-07-21 18:57:48   收藏:0   阅读:4541

使用session方法

###
import winrm
s=winrm.Session(‘http://10.10.60.14:5985/wsman‘,auth=(‘administrator‘,‘password‘))
r=s.run_ps(‘dir‘)
r=s.run_cmd(‘cd /d d: & test.bat‘) 
print r.std_out 
print  r.std_err

使用Protocol方法

###
import winrm
conn = winrm.Protocol(endpoint=‘http://10.10.60.14:5985/wsman‘, transport=‘plaintext‘, username=‘administrator‘, password=‘password‘)

shell_id=conn.open_shell()

com=conn.run_command(shell_id,"dir") 

stdout, stderr, return_code = conn.get_command_output(shell_id, com) 

print "STDOUT: %s" % (stdout)
print "STDERR: %s" % (stderr)


原文:http://zhangxiaohe.blog.51cto.com/7821029/1676780

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!