jborean93 / pypsrp

PowerShell Remoting Protocol for Python
MIT License
324 stars 49 forks source link

Enhancement: Make _utils.py: get_pwsh_script() a more generic method for any PS file #149

Closed ReneH-cnx closed 2 years ago

ReneH-cnx commented 2 years ago

It seems like the function get_pwsh_script() in _utils.py would be really useful for any locally available PowerShell script files that needs to be executed on the remote machine.

Could it be added as a more generic method to one of the classes? I'm not quite sure which one would be best to add it to. Perhaps to PowerShell where add_script() can be found?

jborean93 commented 2 years ago

The util is mostly kept around for finding the ps1 files in the scripts folder. It uses the Python API to get the raw content of Python resources and isn't really designed for reading any file on the filesystem.

In reality it takes 2 lines to read any file locally on your file system

with open("/path/to/local/script.ps1", mode="r") as fd:
    script = fd.read()

Considering the simple nature and extreme flexibility you have by reading the script yourself I'm not sure I see the benefit of doing this inside pypsrp. Appreciate the suggestion but at this point this is not something I plan on implementing sorry.