Skip to main content

The cross-platform tool to execute PowerShell and command line remotely and locally.

Project description

PyPI version Build Status Coverage Status

PyWinOS

The cross-platform tool to work with remote and local Windows OS.

PyWinOS uses the Windows Remote Manager (WinRM) service. It can establish connection to a remote server based on Windows OS and execute commands:

  • PowerShell
  • Command line
  • WMI.

It can execute commands locally using subprocess and command-line too.

For more information on WinRM, please visit Microsoft’s WinRM site It based on pywinrm.

PyWinOS returns object with exit code, stdout and sdtderr response.

Installation

For most users, the recommended method to install is via pip:

pip install pywinos

or from source:

python setup.py install

Import

from pywinos import WinOSClient

Usage (remote server)

Run PowerShell:

from pywinos import WinOSClient

tool = WinOSClient(host='172.16.0.126', username='administrator', password='rds123RDS', logger_enabled=True)
response = tool.run_ps(command='$PSVersionTable.PSVersion')

print(response)  
# ResponseParser(response=(0, 'Major  Minor  Build  Revision\r\n-----  -----  -----  --------\r\n5      1      17763  592', None, '$PSVersionTable.PSVersion'))
print(response.exited)  # 0
print(response.stdout)
# Major  Minor  Build  Revision
# -----  -----  -----  --------
# 5      1      17763  592

# stderr in PowerShell contains some text by default    
print(response.stderr)  # <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Ob...
print(response.ok)  # True

Run command line:

from pywinos import WinOSClient

tool = WinOSClient('172.16.0.126', 'administrator', 'P@ssw0rd', logger_enabled=False)
response = tool.run_cmd(command='whoami')

print(response)  # <Response code 0, out "b'\r\nMajor  Minor  Buil'", err "b''">
print(response.exited)  # 0
print(response.stdout)  # test-vm1\administrator
print(response.stderr)  # None
print(response.ok)  # True

Usage (local server)

Run command line:

from pywinos import WinOSClient

tool = WinOSClient(logger_enabled=False)
# tool = WinOSClient(host='', logger_enabled=False)
# tool = WinOSClient(host='localhost', logger_enabled=False)
# tool = WinOSClient(host='127.0.0.1', logger_enabled=False)
response = tool.run_cmd(command='whoami')

print(response)  # (0, b'mypc\\bobby\r\n', b'')
print(response.exited)  # 0
print(response.stdout)  # my_pc\bobby
print(response.stderr)  # None
print(response.ok)  # True

Helpful predefined methods to work with local Windows OS

  • list_all_methods
  • is_host_available
  • get_current_os_name
  • get_hostname_ip
  • search
  • get_absolute_path
  • get_md5
  • copy
  • unzip
  • remove
  • exists (can check file existing on remote attached network share too)
  • list_dir
  • create_directory
  • clean_directory
  • sort_files (list directory and returns sorted files)
  • timestamp
  • ping
  • get_file_size
  • get_file_version
  • get_last_file_name
  • replace_text (replace text in file)
  • get_local_hostname_ip
  • get_process
  • kill_process
  • get_service
  • is_process_running
  • get_process_memory_info
  • get_process_memory_percent
  • get_process_cpu_percent
  • debug_info (service method to get useful env info)
  • ...

NOTE

Main methods (run_ps and run_cmd) are OS independent. But there are some methods works only on Windows. e.g. get_file_version() depends on pywin32 that available on Windows only.


Changelog

1.0.7 (14.04.2020)
  • .decoded() method added to the response parser
  • warning added if run_ps invoked locally
1.0.6 (06.03.2020)
  • .json() method added to the response parser
1.0.5 (26.01.2020)
  • removed pywin32
1.0.5a (26.01.2020)
  • logging refactored to avoid multiple log entries
1.0.4a (8.01.2020)
  • added attach_share()
1.0.4 (8.01.2020)
  • get_process() method added. Returns 'psutil.Process' class
  • is_process_running() refactored.
  • get_process_memory_info() method added: returns namedtuple. Full - optional parameter that work with admin rights only. Else returns brief memory info!
  • get_process_memory_percent() method added.
  • get_process_cpu_percent() method added.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pywinos-1.0.7.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pywinos-1.0.7-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file pywinos-1.0.7.tar.gz.

File metadata

  • Download URL: pywinos-1.0.7.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.1

File hashes

Hashes for pywinos-1.0.7.tar.gz
Algorithm Hash digest
SHA256 a489ccba34737b867171440da5553d4f2930ab84f66cc137e84df244b8bfb796
MD5 41b127bfff9378c203a027d54bad88ca
BLAKE2b-256 aaed1455709db678d57c6d51fdafe73663da8694de3eb29028e1988c19cb0451

See more details on using hashes here.

File details

Details for the file pywinos-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: pywinos-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.1

File hashes

Hashes for pywinos-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 ba349ae5e6d6b49efd895d124b4f6bf4027b5cd72e4756dfeb2475d426fbf807
MD5 62fe596dfdbde9d6e924cf5a626cae01
BLAKE2b-256 3fc46ccde80f0829a7c0c7103ac3579b5c5881fc77835f42d4b554f8e1d62f73

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page