Skip to content

Instantly share code, notes, and snippets.

@NZSmartie
Created October 5, 2018 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NZSmartie/1023661c920e9f344b9f14aa0fbfc068 to your computer and use it in GitHub Desktop.
Save NZSmartie/1023661c920e9f344b9f14aa0fbfc068 to your computer and use it in GitHub Desktop.
Test WinRM command from a python2 script
#! /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