Skip to content

Commit

Permalink
Support PowerShell (fixed #40)
Browse files Browse the repository at this point in the history
  • Loading branch information
markuslf committed Nov 16, 2021
1 parent 91ec8a2 commit c66de91
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions powershell3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#! /usr/bin/env python2
# -*- coding: utf-8; py-indent-offset: 4 -*-
#
# Author: Linuxfabrik GmbH, Zurich, Switzerland
# Contact: info (at) linuxfabrik (dot) ch
# https://www.linuxfabrik.ch/
# License: The Unlicense, see LICENSE file.

# https://git.linuxfabrik.ch/linuxfabrik-icinga-plugins/checks-linux/-/blob/master/CONTRIBUTING.md

"""This library collects some Microsoft PowerShell related functions.
"""

__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2021111501'

import subprocess


def run_cmdlet(cmd):
"""
You will need PowerShell installed on your system and Python 3.6+.
This would work cross-platform. No need for external libraries.
Returns
* result.args (list)
* result.returncode: 0 = ok
* result.stdout: Byte-String
* result.stderr: Byte-String
"""
result = subprocess.run(['powershell', '-Command', cmd], capture_output=True)
return {
'args': result.args,
'retc': result.returncode,
'stdout': result.stdout.decode(), # convert from byte to unicode
'stderr': result.stderr.decode(), # convert from byte to unicode
}

0 comments on commit c66de91

Please sign in to comment.