pxpowershell
This module lets you interact with a Powershell Prompt from Python. It is intended to provide similar functionality to "pxssh" or "redexpect" but for Powershell.
Why not subprocess? Subprocess does something different. It executes a single process and captures the output. pxpowershell lets you enstantiate a powershell process and then interact with it. Variables are saved form command to command. Functions defined in one command can be called later and so forth.
Usage
x = pxpowershell()
x.start_process()
x.run("$a = 10000")
print(x.run("$a + 1"))
result = x.run("get-process")
print(result)
x.stop_process()
Installing
I recommending setuping up a virtual machine (although not required)
c:\> py -m venv \path\to\new\venv\folder
c:\> \path\to\new\venv\folder\bin\activate.bat
Then pip install:
c:\> py -m pip install git+https://github.com/markbaggett/pxpowershell
Example
If you used a virtual environment so the install can run properly you now have a new command line utility called "dir2iso" installed:
(pxpowershell) C:\Users\User\Documents\GitHub\pxpowershell>dir2iso --help
usage: dir2iso [-h] source destination title
positional arguments:
source The path to the directory to turn into an ISO
destination The destination ISO file to create (including path).
title The title of the ISO.
optional arguments:
-h, --help show this help message and exit
This utility will create a .ISO file containing the specified directory. This is done using a demonstration script to shows how easily you can interact with Powershell. The Powershell Script that does all the real work came from @wikijm. Buy him a coffee.
https://github.com/wikijm/PowerShell-AdminScripts/blob/master/Miscellaneous/New-IsoFile.ps1
Here is everything the script really does:
def dir2iso(src, dest, title="Created by pxpowershell"):
pshell = pxpowershell.PxPowershell(debug=False)
x = pshell.start_process()
x = pshell.run(powershell_script, 10)
x = pshell.run(f"cd {src}")
result = pshell.run(f"New-IsoFile {src} -path {dest} -title {title} -Force", 60*60)
result = pshell.run(f"ls {dest}")
pshell.stop_process()
return result
You start the powershell process. We send in the new-isofile script, then execute it capturing the results. Notice that each call to .run passes the command to send to powershell and a timeout to wait for the command to finish and return to the Powershell Prompt. If no timeout is provided the default is 3 seconds.
Metadata
Release files for pxpowershell 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pxpowershell-1.0.0.tar.gz | 5.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pxpowershell-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.6 kB
Release files / pxpowershell-1.0.0.tar.gz
| Download URL | pxpowershell-1.0.0.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c470e48bef39b3aaa90475afbe7805bfa2af44c45a658d48876db7a2af26e0fe
|
|
BLAKE2b-256 checksum How to use checksums |
446013ec142a1e109075d2d0adb52f527b80fae161c9aa2522e2aad363ba2264
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
|
Release files / pxpowershell-1.0.0-py3-none-any.whl
| Download URL | pxpowershell-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c5b5a25dcbd6c59a1a7a9a2a380b2a561369f0c223ef942a76d941762b57472e
|
|
BLAKE2b-256 checksum How to use checksums |
e388be6d1b5dd4533f877cbe3975df28bd52ad21cc981a8a27a2dfb915fb6e0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
|
Security for pxpowershell 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.