Created
October 5, 2018 02:16
-
-
Save NZSmartie/1023661c920e9f344b9f14aa0fbfc068 to your computer and use it in GitHub Desktop.
Test WinRM command from a python2 script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python2 | |
from __future__ import print_function | |
import getpass | |
from winrm.protocol import Protocol | |
conn = Protocol( | |
endpoint='https://dc.example.com:5986/wsman', | |
transport='ntlm', | |
username='NZSmartie', | |
password=getpass.getpass('Password for NZSmartie: '), | |
server_cert_validation='ignore') | |
shell_id = conn.open_shell() | |
print(shell_id) | |
command_id = conn.run_command(shell_id, 'ipconfig', ['/all']) | |
print(conn.get_command_output(shell_id, command_id)) | |
conn.cleanup_command(shell_id, command_id) | |
conn.close_shell(shell_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment