You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

57 lines
1.2 KiB

#!/usr/bin/env python3
import sys
import os
import winrm
us = 'Administrator'
try:
us = os.environ['us']
except:
pass
pw = None
pwf = None
try:
pwf = os.environ['pwf']
except:
pass
if pwf:
with open(pwf, 'rb') as pwfh:
pw = pwfh.read().rstrip()
try:
if pw is None:
pw = os.environ['pw']
except:
import getpass
pw = getpass.getpass("Password: ")
from winrm.protocol import Protocol
host = sys.argv[1]
del sys.argv[1]
p = Protocol(
endpoint='https://%s:5986/wsman' % host,
transport='ntlm',
username=us,
password=pw,
server_cert_validation='ignore')
shell_id = p.open_shell()
# command_id = p.run_command(shell_id, 'ipconfig', ['/all'],
# out_stream=sys.stdout, err_stream=sys.stderr)
# command_id = p.run_command(shell_id, 'ipconfig', ['/all'], console_mode_stdin=False)
command_id = p.run_command(shell_id, sys.argv[1], sys.argv[2:], console_mode_stdin=True)
std_out, std_err, status_code = p.get_command_output(shell_id, command_id)
p.cleanup_command(shell_id, command_id)
p.close_shell(shell_id)
if std_out:
print(std_out.decode('utf-8'))
if std_err:
print(std_err.decode('utf-8'))
sys.exit(status_code)